package com.controller.device;

import com.common.ErrorCodeEnum;
import com.common.anntation.Log;
import com.common.emums.BusinessType;
import com.common.exception.BusinessException;
import com.common.utils.*;
import com.common.utils.file.FileUtils;
import com.common.utils.test.SocketTest;
import com.core.springSecurity.common.SecurityUtils;
import com.core.springSecurity.model.LoginUserDetails;
import com.github.pagehelper.PageInfo;
import com.model.base.PageResult;
import com.model.base.Result;
import com.model.domain.data.GetDataObdTcpLogInfoDO;
import com.model.domain.device.*;
import com.model.domain.machine.GetMachineInfoDO;
import com.model.domain.user.GetUserInfoDO;
import com.model.dto.device.deviceInfo.*;
import com.model.pojo.data.DataObdTcpLogInfo;
import com.model.pojo.device.*;
import com.model.pojo.machine.MachineInfo;
import com.model.pojo.sys.SysUser;
import com.model.pojo.user.UserInfo;
import com.model.vo.device.deviceInfo.getDayInfo.GetDayInfoVO;
import com.model.vo.device.deviceInfo.getDeviceDistributionInApp.GetDeviceDistributionInAppVO;
import com.model.vo.device.deviceInfo.getDistributeInfo.GetDistributeInfoVO;
import com.model.vo.device.deviceInfo.getErrorImgInfo.GetErrorImgInfoListVO;
import com.model.vo.device.deviceInfo.getErrorImgInfo.GetErrorImgInfoVO;
import com.model.vo.device.deviceInfo.getImgInfo.GetImgInfoListVO;
import com.model.vo.device.deviceInfo.getImgInfo.GetImgInfoVO;
import com.model.vo.device.deviceInfo.getPointInfo.GetPointInfoVO;
import com.model.vo.device.deviceInfo.getTrackInfo.GetTrackInfoListVO;
import com.model.vo.device.deviceInfo.getTrackInfo.GetTrackInfoVO;
import com.model.vo.device.deviceInfo.getWorkDailyInfo.GetWorkDailyInfoVO;
import com.model.vo.device.deviceInfo.getDeviceListByGpsError.GetDeviceListByGpsErrorVO;
import com.model.vo.device.deviceOBDInfo.getDeviceList.GetDeviceListVO;
import com.model.vo.device.getDeviceListInApp.GetDeviceListInAppVO;
import com.service.data.DataObdTcpLogInfoService;
import com.service.device.*;
import com.service.machine.MachineInfoService;
import com.service.sys.SysUserService;
import com.service.user.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * TODO
 *
 * @Description
 * @Author tm
 * @Date 2023-06-07 1:10
 **/
@Api(tags = {"设备管理"})
@Slf4j
@RestController
@RequestMapping("/v2/device")
@RequiredArgsConstructor
public class DeviceInfoController {
    private final DevicePcbGpsInfoService devicePcbGpsInfoService;
    private final DeviceObdGpsInfoService deviceObdGpsInfoService;
    private final DevicePmdGpsInfoService devicePmdGpsInfoService;
    private final DevicePcbGpsImgInfoService devicePcbGpsImgInfoService;
    private final DevicePmdGpsImgInfoService devicePmdGpsImgInfoService;
    private final DevicePcbDayInfoService devicePcbDayInfoService;
    private final DeviceObdDayInfoService deviceObdDayInfoService;
    private final DevicePmdDayInfoService devicePmdDayInfoService;
    private final DeviceObdBaseInfoService deviceObdBaseInfoService;
    private final DevicePcbBaseInfoService devicePcbBaseInfoService;
    private final DevicePmdBaseInfoService devicePmdBaseInfoService;
    private final DeviceObdWorkDailyRecordInfoService deviceObdWorkDailyRecordInfoService;
    private final DevicePcbWorkDailyRecordInfoService devicePcbWorkDailyRecordInfoService;
    private final DevicePmdWorkDailyRecordInfoService devicePmdWorkDailyRecordInfoService;
    private final Device25ObdInfoService device25ObdInfoService;
    private final DeviceObdGkDayInfoService deviceObdGkDayInfoService;
    private final DeviceObdTcpLogInfoService deviceObdTcpLogInfoService;
    private final DataObdTcpLogInfoService dataObdTcpLogInfoService;
    private final DeviceObdExFactoryBatchInfoService deviceObdExFactoryBatchInfoService;
    private final UserInfoService userInfoService;
    private final DeviceGpsErrorStatisticsInfoService deviceGpsErrorStatisticsInfoService;
    private final MachineInfoService machineInfoService;
    private final SysUserService sysUserService;

    @Log(title = "设备管理-农机分布", businessType = BusinessType.INSERT)
    @ApiOperation(value = "农机分布")
    @PostMapping("/getDistributeInfo")
    public Result<List<GetDistributeInfoVO>> getDistributeInfo(@RequestBody @Valid GetDistributeInfoDTO dto) {
        int queryType = 0;//查询类型 0全部，1TBOX，2安卓版 3播种机
        if (dto.getType() != null) {
            queryType = dto.getType();
        }
        LoginUserDetails loginUserDetails = SecurityUtils.getLoginUser();
//        long userId = 0;
//        String userName = "";
        if (loginUserDetails != null) {
            SysUser sysUser = loginUserDetails.getUser();
            if (sysUser != null) {
//                userId = sysUser.getUserId();
//                userName = sysUser.getName();
                if (queryType == 0) {
                    switch (sysUser.getUserType()) {
                        case Constants.SysUserUserType.TYPE_TBOX生产厂家:
                        case Constants.SysUserUserType.TYPE_TBOX生产厂家2:
                        case Constants.SysUserUserType.TYPE_TBOX经销商:
                        case Constants.SysUserUserType.TYPE_厂家配置:
                            queryType = 1;
                            break;
                        case Constants.SysUserUserType.TYPE_播种机查看权限:
                        case Constants.SysUserUserType.TYPE_播种机生产厂家:
                        case Constants.SysUserUserType.TYPE_播种机经销商:
                            queryType = 3;
                            break;
                        default:
                            break;
                    }
                }
            }
            /*if ((sysUser.getUserType() == 2 || sysUser.getUserType() == 4) && !"testadmin".equals(sysUser.getName()) && sysUser.getUserId() != null) {
                isObdFactory = true;
                userId = sysUser.getUserId();
                userName = sysUser.getName();
            }*/
        }
        List<GetDistributeInfoVO> voList = new ArrayList<>();
        if (queryType == 0 || queryType == 1) {
            GetDeviceObdBaseInfoDO getDeviceObdBaseInfoDO = new GetDeviceObdBaseInfoDO();//EntityConversionUtil.copy(dto, GetDeviceObdBaseInfoDO.class);
            getDeviceObdBaseInfoDO.setDtu(dto.getDtu());
            if (dto.getFactoryUserId() != null) {
                UserInfo userInfo = userInfoService.getById(dto.getFactoryUserId());
                if (userInfo != null && userInfo.getAllowSecondSupply() == 1) {//如果筛选的厂家的是可以二次供销的
                    getDeviceObdBaseInfoDO.setFactoryUserId(null);
                    List<Long> batchIds = new ArrayList<>();
                    GetDeviceObdExFactoryBatchInfoDO getDeviceObdExFactoryBatchInfoDO = new GetDeviceObdExFactoryBatchInfoDO();
                    getDeviceObdExFactoryBatchInfoDO.setFactoryUserId(dto.getFactoryUserId());
                    getDeviceObdExFactoryBatchInfoDO.setSortRow("createTime");
                    List<DeviceObdExFactoryBatchInfo> batchList = deviceObdExFactoryBatchInfoService.getAllList(getDeviceObdExFactoryBatchInfoDO);
                    if (batchList != null && batchList.size() > 0) {
                        batchIds = batchList.stream().map(DeviceObdExFactoryBatchInfo::getBatchId).collect(Collectors.toList());
                    } else {
                        batchIds.add(0l);
                    }
                    getDeviceObdBaseInfoDO.setBatchIds(batchIds);
                } else {
                    getDeviceObdBaseInfoDO.setFactoryUserId(dto.getFactoryUserId());
                }
            } else {
                if (loginUserDetails != null && loginUserDetails.getUser() != null && loginUserDetails.getUser().getUserId() != null) {
                    SysUser sysUser = loginUserDetails.getUser();
                    long userId = sysUser.getUserId();
                    String userName = sysUser.getName();
                    if(sysUser.getUserType() == Constants.SysUserUserType.TYPE_TBOX生产厂家 || sysUser.getUserType() == Constants.SysUserUserType.TYPE_TBOX生产厂家2){
                        if ("15210999919".equals(userName)) {
                            getDeviceObdBaseInfoDO.setFactoryUserId(null);
                            getDeviceObdBaseInfoDO.setPrefix("02");
                        } else {
                            getDeviceObdBaseInfoDO.setFactoryUserId(userId);
                        }
                    } else if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_厂家配置) {
                        UserInfo userInfo = userInfoService.getById(userId);
                        if (userInfo != null && userInfo.getAllowSecondSupply() == 1) {
                            getDeviceObdBaseInfoDO.setFactoryUserId(null);
                            List<Long> batchIds = new ArrayList<>();
                            GetDeviceObdExFactoryBatchInfoDO getDeviceObdExFactoryBatchInfoDO = new GetDeviceObdExFactoryBatchInfoDO();
                            getDeviceObdExFactoryBatchInfoDO.setFactoryUserId(userId);
                            getDeviceObdExFactoryBatchInfoDO.setSortRow("createTime");
                            List<DeviceObdExFactoryBatchInfo> batchList = deviceObdExFactoryBatchInfoService.getAllList(getDeviceObdExFactoryBatchInfoDO);
                            if (batchList != null && batchList.size() > 0) {
                                batchIds = batchList.stream().map(DeviceObdExFactoryBatchInfo::getBatchId).collect(Collectors.toList());
                            } else {
                                batchIds.add(0l);
                            }
                            getDeviceObdBaseInfoDO.setBatchIds(batchIds);
                        }
                    }
                }
            }
            /*if (queryType == 1) {
                if(getDeviceObdBaseInfoDO.getFactoryUserId()==null)getDeviceObdBaseInfoDO.setFactoryUserId(userId);
                //处理可二次销售厂家的情况
                UserInfo userInfo = userInfoService.getById(userId);
                if (userInfo != null && userInfo.getAllowSecondSupply() == 1) {
                    getDeviceObdBaseInfoDO.setFactoryUserId(null);
                    List<Long> batchIds = new ArrayList<>();
                    GetDeviceObdExFactoryBatchInfoDO getDeviceObdExFactoryBatchInfoDO = new GetDeviceObdExFactoryBatchInfoDO();
                    getDeviceObdExFactoryBatchInfoDO.setFactoryUserId(userId);
                    getDeviceObdExFactoryBatchInfoDO.setSortRow("createTime");
                    List<DeviceObdExFactoryBatchInfo> batchList = deviceObdExFactoryBatchInfoService.getAllList(getDeviceObdExFactoryBatchInfoDO);
                    if (batchList != null && batchList.size() > 0) {
                        batchIds = batchList.stream().map(DeviceObdExFactoryBatchInfo::getBatchId).collect(Collectors.toList());
                    } else {
                        batchIds.add(0l);
                    }
                    getDeviceObdBaseInfoDO.setBatchIds(batchIds);
                }
            }
            //特殊处理
            if ("15210999919".equals(userName)) {
                getDeviceObdBaseInfoDO.setFactoryUserId(null);
                getDeviceObdBaseInfoDO.setPrefix("02");
            }*/
            getDeviceObdBaseInfoDO.setSortRow("id");
            getDeviceObdBaseInfoDO.setSortOrder("desc");
            List<DeviceObdBaseInfo> obdBaseList = deviceObdBaseInfoService.getAllList(getDeviceObdBaseInfoDO);
            if (obdBaseList != null && obdBaseList.size() > 0) {
                obdBaseList.forEach(item -> {
                    if (StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && !"0.0".equals(item.getLon()) && !"0.0".equals(item.getLat())) {
                        GetDistributeInfoVO vo = EntityConversionUtil.copy(item, GetDistributeInfoVO.class);
                        vo.setTime(item.getDataTime());
                        vo.setType(1);
                        voList.add(vo);
                    }
                });
            }
        }
        if (queryType == 0 || queryType == 2) {
            GetDevicePcbBaseInfoDO getDevicePcbBaseInfoDO = EntityConversionUtil.copy(dto, GetDevicePcbBaseInfoDO.class);
            if (loginUserDetails != null && loginUserDetails.getUser() != null && loginUserDetails.getUser().getUserId() != null) {
                SysUser sysUser = loginUserDetails.getUser();
                if (sysUser.getUserType() != Constants.SysUserUserType.TYPE_管理员 && sysUser.getUserType() != Constants.SysUserUserType.TYPE_车间生产) {
                    getDevicePcbBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                }
            }
            getDevicePcbBaseInfoDO.setSortRow("id");
            getDevicePcbBaseInfoDO.setSortOrder("desc");
            List<DevicePcbBaseInfo> pcbBaseList = devicePcbBaseInfoService.getAllList(getDevicePcbBaseInfoDO);
            if (pcbBaseList != null && pcbBaseList.size() > 0) {
                pcbBaseList.forEach(item -> {
                    if (StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && !"0.0".equals(item.getLon()) && !"0.0".equals(item.getLat())) {
                        GetDistributeInfoVO vo = EntityConversionUtil.copy(item, GetDistributeInfoVO.class);
                        vo.setTime(item.getDataTime());
                        vo.setType(2);
                        voList.add(vo);
                    }
                });
            }
        }

        if (queryType == 0 || queryType == 3) {
            GetDevicePmdBaseInfoDO getDevicePmdBaseInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdBaseInfoDO.class);
            if (loginUserDetails != null && loginUserDetails.getUser() != null) {
                SysUser sysUser = loginUserDetails.getUser();
                if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机查看权限) {
                    List<Long> factoryUserIds = new ArrayList<>();
                    factoryUserIds.add(0l);
                    GetUserInfoDO getUserInfoDO = new GetUserInfoDO();
                    getUserInfoDO.setUserType(1);
                    getUserInfoDO.setDeviceType(3);
                    getUserInfoDO.setSortRow("id");
                    List<UserInfo> userList = userInfoService.getAllList(getUserInfoDO);
                    if (userList != null && userList.size() > 0) {
                        factoryUserIds = userList.stream().map(UserInfo::getId).collect(Collectors.toList());
                    }
                    getDevicePmdBaseInfoDO.setFactoryUserIds(factoryUserIds);
                }
                if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机生产厂家) {
                    getDevicePmdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                }
                //经销商帐号过滤
                if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机经销商) {
                    List<String> dtus = new ArrayList<>();
                    dtus.add("0");
                    GetMachineInfoDO getMachineInfoDO = new GetMachineInfoDO();
                    getMachineInfoDO.setDealerUserId(sysUser.getUserId());
                    getMachineInfoDO.setSortRow("id");
                    List<MachineInfo> machineList = machineInfoService.getAllList(getMachineInfoDO);
                    if (machineList != null && machineList.size() > 0) {
                        dtus = machineList.stream().map(MachineInfo::getTerminalNum).collect(Collectors.toList());
                    }
                    getDevicePmdBaseInfoDO.setDtus(dtus);
                }
            }
            getDevicePmdBaseInfoDO.setSortRow("id");
            getDevicePmdBaseInfoDO.setSortOrder("desc");
            List<DevicePmdBaseInfo> pmdBaseList = devicePmdBaseInfoService.getAllList(getDevicePmdBaseInfoDO);
            if (pmdBaseList != null && pmdBaseList.size() > 0) {
                pmdBaseList.forEach(item -> {
                    if (StringUtils.isNotBlank(item.getLon()) && StringUtils.isNotBlank(item.getLat()) && !"0.0".equals(item.getLon()) && !"0.0".equals(item.getLat())) {
                        GetDistributeInfoVO vo = EntityConversionUtil.copy(item, GetDistributeInfoVO.class);
                        vo.setTime(item.getLastDataTime());
                        vo.setType(3);
                        voList.add(vo);
                    }
                });
            }
        }
        return Result.suc(voList);
    }

    @Log(title = "设备管理-终端轨迹信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "终端轨迹信息")
    @PostMapping("/getTrackInfo")
    @CrossOrigin
    public Result<GetTrackInfoVO> getTrackInfo(@RequestBody @Valid GetTrackInfoDTO dto) {
        if (StringUtils.isBlank(dto.getTime())) {
            return Result.fail("9999", "请提交查询日期");
        }
        GetTrackInfoVO vo = new GetTrackInfoVO();

        if (dto.getType() == 1) {//OBD设备
            vo = getObdTrackInfo(dto);
        } else if (dto.getType() == 2) {//安卓版
            vo = getPcbTrackInfo(dto);
        } else if (dto.getType() == 3) {//播种机
            vo = getPmdTrackInfo(dto);
        }
        return Result.suc(vo);
    }

    @Log(title = "设备管理-获取设备每天的记录信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "获取设备每天的记录信息")
    @PostMapping("/getDayInfo")
    @CrossOrigin
    public Result<List<GetDayInfoVO>> getDayInfo(@RequestBody @Valid GetDayInfoDTO dto) {
        List<GetDayInfoVO> voList = new ArrayList<>();
        if (dto.getType() == 1) {//OBD设备
            GetDeviceObdDayInfoDO getDeviceObdDayInfoDO = EntityConversionUtil.copy(dto, GetDeviceObdDayInfoDO.class);
            List<DeviceObdDayInfo> dayList = deviceObdDayInfoService.getAll(getDeviceObdDayInfoDO);
            if (dayList != null && dayList.size() > 0) {
                voList = EntityConversionUtil.copyList(dayList, GetDayInfoVO.class);
            }
        } else if (dto.getType() == 2) {//安卓版
            GetDevicePcbDayInfoDO getDevicePcbDayInfoDO = EntityConversionUtil.copy(dto, GetDevicePcbDayInfoDO.class);
            List<DevicePcbDayInfo> dayList = devicePcbDayInfoService.getAll(getDevicePcbDayInfoDO);
            if (dayList != null && dayList.size() > 0) {
                voList = EntityConversionUtil.copyList(dayList, GetDayInfoVO.class);
            }
        } else if (dto.getType() == 3) {//播种机
            GetDevicePmdDayInfoDO getDevicePmdDayInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdDayInfoDO.class);
            List<DevicePmdDayInfo> dayList = devicePmdDayInfoService.getAll(getDevicePmdDayInfoDO);
            if (dayList != null && dayList.size() > 0) {
                voList = EntityConversionUtil.copyList(dayList, GetDayInfoVO.class);
            }
        }
        return Result.suc(voList);
    }

    @Log(title = "设备管理-终端图片信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "终端图片信息")
    @PostMapping("/getImgInfo")
    @CrossOrigin
    public Result<GetImgInfoVO> getImgInfo(@RequestBody @Valid GetImgInfoDTO dto) {
        GetImgInfoVO vo = new GetImgInfoVO();
        if (dto.getTime() == null || "".equals(dto.getTime())) {
            return Result.fail("9999", "请提交查询日期");
        }
        if (dto.getType() == 1) {//OBD设备
        } else if (dto.getType() == 2) {//安卓版
            vo = getPcbImgInfo(dto);
        } else if (dto.getType() == 3) {//播种机
            vo = getPmdImgInfo(dto);
        }
        return Result.suc(vo);
    }

    @Log(title = "设备管理-终端错误图片信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "终端错误图片信息")
    @PostMapping("/getErrorImgInfo")
    @CrossOrigin
    public Result<GetErrorImgInfoVO> getErrorImgInfo(@RequestBody @Valid GetErrorImgInfoDTO dto) {
        GetErrorImgInfoVO vo = new GetErrorImgInfoVO();
        if (dto.getTime() == null || "".equals(dto.getTime())) {
            return Result.fail("9999", "请提交查询日期");
        }
        if (dto.getType() == 2) {//安卓版
            vo = getPcbErrorImgInfo(dto);
        } else if (dto.getType() == 3) {//播种机
        }
        return Result.suc(vo);
    }

    @Log(title = "设备管理-定位点详细信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "定位点详细信息")
    @PostMapping("/getPointInfo")
    @CrossOrigin
    public Result<List<GetPointInfoVO>> getPointInfo(@RequestBody @Valid GetPointInfoDTO dto) {
        List<GetPointInfoVO> voList = new ArrayList<>();
        if (dto.getType() == 1) {//OBD设备
            voList = getObdPointInfo(dto);
        } else if (dto.getType() == 2) {//安卓设备
            voList = getPcbPointInfo(dto);
        } else if (dto.getType() == 3) {//播种机
            voList = getPmdPointInfo(dto);
        }
        return Result.suc(voList);
    }

    /**
     * 获取OBD的定位详细信息
     *
     * @param dto
     * @return List<GetPointInfoVO>
     * @author tm
     * @date 2023-06-10 19:25
     */
    private List<GetPointInfoVO> getObdPointInfo(GetPointInfoDTO dto) {
        List<GetPointInfoVO> voList = new ArrayList<>();
        String tableName = "device_obd_gps_info_";
        tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
        DeviceObdGpsInfo info = deviceObdGpsInfoService.getById(tableName, dto.getId());
        if (info != null && info.getId() > 0) {
            GetPointInfoVO vo = new GetPointInfoVO();
            vo.setName("作业时间");
            vo.setValue(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, info.getTime()));
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("速度(KM/H)");
            BigDecimal speed = new BigDecimal(info.getSpeed());//new BigDecimal(info.getSpeed()).multiply(new BigDecimal(1.852)).setScale(2,BigDecimal.ROUND_HALF_DOWN);
            vo.setValue(speed + "");
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("经度");
            vo.setValue(info.getLon());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("纬度");
            vo.setValue(info.getLat());
            voList.add(vo);
        }
        return voList;
    }

    /**
     * 获取安卓版的定位详细信息
     *
     * @param dto
     * @return List<GetPointInfoVO>
     * @author tm
     * @date 2023-06-10 19:25
     */
    private List<GetPointInfoVO> getPcbPointInfo(GetPointInfoDTO dto) {
        List<GetPointInfoVO> voList = new ArrayList<>();
        String tableName = "device_pcb_gps_info_";
        tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
        DevicePcbGpsInfo info = devicePcbGpsInfoService.getById(tableName, dto.getId());
        if (info != null && info.getId() > 0) {
            GetPointInfoVO vo = new GetPointInfoVO();
            vo.setName("作业时间");
            vo.setValue(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, info.getTime()));
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("速度(KM/H)");
            BigDecimal speed = new BigDecimal(info.getSpeed()).multiply(new BigDecimal(1.852)).setScale(2, BigDecimal.ROUND_HALF_DOWN);
            vo.setValue(speed + "");
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("经度");
            vo.setValue(info.getLon());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("纬度");
            vo.setValue(info.getLat());
            voList.add(vo);
            if ("5525".equals(info.getBizCode()) || "552C".equals(info.getBizCode())) {
                vo = new GetPointInfoVO();
                vo.setName("耕深值(CM)");
                vo.setValue((Float.valueOf(info.getIsWork()) / 10) + "");
                voList.add(vo);
            }

        }
        return voList;
    }


    /**
     * 获取播种机的定位详细信息
     *
     * @param dto
     * @return List<GetPointInfoVO>
     * @author tm
     * @date 2023-06-10 19:25
     */
    private List<GetPointInfoVO> getPmdPointInfo(GetPointInfoDTO dto) {
        List<GetPointInfoVO> voList = new ArrayList<>();
        String tableName = "device_pmd_gps_info_";
        tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
        DevicePmdGpsInfo info = devicePmdGpsInfoService.getById(tableName, dto.getId());
        if (info != null && info.getId() > 0) {
            GetPointInfoVO vo = new GetPointInfoVO();
            vo.setName("作业时间");
            vo.setValue(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, info.getTime()));
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("速度(KM/H)");
            BigDecimal speed = new BigDecimal(info.getSpeed()).multiply(new BigDecimal(1.852)).setScale(2, BigDecimal.ROUND_HALF_DOWN);
            vo.setValue(speed + "");
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("经度");
            vo.setValue(info.getLon());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("纬度");
            vo.setValue(info.getLat());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("行距(CM)");
            vo.setValue(info.getRowSpacing());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("株距(CM)");
            vo.setValue(info.getPlantSpacing());
            voList.add(vo);

            vo = new GetPointInfoVO();
            vo.setName("通道数量");
            vo.setValue(info.getPassageNum());
            voList.add(vo);

            String content = info.getContent();
            String[] cStr = content.split("\\|");
            if (cStr.length > 12) {
                vo = new GetPointInfoVO();
                vo.setName("面积(亩)");
                vo.setValue(cStr[11]);
                voList.add(vo);
                int number = Integer.parseInt(cStr[12]);
                for (int i = 1; i < number + 1; i++) {
                    int index = 12 + i;
                    String c = cStr[index];
                    String name = "通道" + i;
                    String status = c.substring(c.length() - 1, c.length());
                    int num = Integer.parseInt(c.substring(0, c.length() - 1));
                    String value = num + "";
                    if ("N".equals(status)) {
                        continue;
                    } else if ("C".equals(status)) {
                        value += " (关闭)";
                    } else if ("L".equals(status)) {
                        value += " (漏播) ";
                    } else if ("S".equals(status)) {
                        value += " (探头有灰) ";
                    } else if ("U".equals(status)) {
                        value += " (未安装) ";
                    }
                    vo = new GetPointInfoVO();
                    vo.setName(name);
                    vo.setValue(value);
                    voList.add(vo);
                }
            }
        }
        return voList;
    }

    /**
     * 获取OBD设备轨迹
     *
     * @param dto
     * @return GetTrackInfoVO
     * @author tm
     * @date 2023-06-08 22:02
     */
    private GetTrackInfoVO getObdTrackInfo(GetTrackInfoDTO dto) {
        GetTrackInfoVO vo = new GetTrackInfoVO();
        List<String> colors = getColorList();
        vo.setColors(colors);
        List<GetTrackInfoListVO> trackList = new ArrayList<>();
        List<DeviceObdGpsInfo> gpsList = new ArrayList<>();
        String userName = "";
        boolean isObdFactory = false;
        try {
            LoginUserDetails loginUserDetails = SecurityUtils.getLoginUser();
            SysUser sysUser = loginUserDetails.getUser();
            userName = sysUser.getName();
            if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_TBOX生产厂家 || sysUser.getUserType() == Constants.SysUserUserType.TYPE_TBOX生产厂家2) {//OBD生产厂家
                isObdFactory = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
            //特殊处理
            if ("15210999919".equals(userName)) {
                if (DateUtils.calDay(DateUtils.parseStrToDate(dto.getStartTime(), DateUtils.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS), new Date()) > 3) {
                    throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                }
                if (DateUtils.calDay(DateUtils.parseStrToDate(dto.getEndTime(), DateUtils.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS), new Date()) > 3) {
                    throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                }
            }
            //生产厂家
            if (isObdFactory) {
                DeviceObdBaseInfo baseInfo = deviceObdBaseInfoService.getByDtu(dto.getDtu());
                if (baseInfo != null && baseInfo.getBatchId() != null && baseInfo.getBatchId() > 0) {
                    DeviceObdExFactoryBatchInfo batchInfo = deviceObdExFactoryBatchInfoService.getById(baseInfo.getBatchId());
                    if (batchInfo == null || batchInfo.getExFactory() == 0) {
//                        throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                        return vo;
                    }
                    //查询的日期为出厂前的
                    if (DateUtils.compareTwoTimeBefore(DateUtils.parseStrToDate(dto.getStartTime(), DateUtils.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS), batchInfo.getExDate())) {
//                        throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                        return vo;
                    }
                }
            }
            String startTime = dto.getStartTime();
            String endTime = dto.getEndTime();
            String dtu = dto.getDtu();
            boolean flag = true;
            Date startDate = DateUtils.parseStrToDate(startTime, DateUtils.YYYY_MM_DD_HH_MM_SS);
            Date endDate = DateUtils.parseStrToDate(endTime, DateUtils.YYYY_MM_DD_HH_MM_SS);
            while (flag) {
                System.out.println("startDate :" + startDate);
                System.out.println("endDate :" + endDate);
                if (DateUtils.compareIsSameDay(startDate, endDate)) {
                    GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                    getDeviceObdGpsInfoDO.setDtu(dto.getDtu());
                    String tableName = "device_obd_gps_info_" + DateUtils.parseDateToStr(DateUtils.YYYYMMDD, startDate);
                    getDeviceObdGpsInfoDO.setSTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate));
                    getDeviceObdGpsInfoDO.setETime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate));
                    getDeviceObdGpsInfoDO.setSortRow("time");
                    getDeviceObdGpsInfoDO.setSortOrder("asc");
                    getDeviceObdGpsInfoDO.setTableName(tableName);
                    getDeviceObdGpsInfoDO.setIsEffective("1");
                    List<DeviceObdGpsInfo> tempList = deviceObdGpsInfoService.getAllList(getDeviceObdGpsInfoDO);
                    if (tempList != null && tempList.size() > 0) {
                        gpsList.addAll(tempList);
                    }
                    flag = false;
                } else {
                    GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                    getDeviceObdGpsInfoDO.setDtu(dto.getDtu());
                    String tableName = "device_obd_gps_info_" + DateUtils.parseDateToStr(DateUtils.YYYYMMDD, startDate);
                    String eTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startDate) + " 23:59:59";
                    getDeviceObdGpsInfoDO.setSTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate));
                    getDeviceObdGpsInfoDO.setETime(eTime);
                    getDeviceObdGpsInfoDO.setSortRow("time");
                    getDeviceObdGpsInfoDO.setSortOrder("asc");
                    getDeviceObdGpsInfoDO.setTableName(tableName);
                    getDeviceObdGpsInfoDO.setIsEffective("1");
                    List<DeviceObdGpsInfo> tempList = deviceObdGpsInfoService.getAllList(getDeviceObdGpsInfoDO);
                    if (tempList != null && tempList.size() > 0) {
                        gpsList.addAll(tempList);
                    }
                    String tempStartDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(startDate, 1)) + " 00:00:00";
                    startDate = DateUtils.parseStrToDate(tempStartDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
                }
            }
        } else if (StringUtils.isNotBlank(dto.getTime())) {
            //特殊处理
            if ("15210999919".equals(userName)) {
                if (DateUtils.calDay(DateUtils.parseStrToDate(dto.getTime(), DateUtils.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS), new Date()) > 3) {
                    throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                }
            }
            //生产厂家
            if (isObdFactory) {
                DeviceObdBaseInfo baseInfo = deviceObdBaseInfoService.getByDtu(dto.getDtu());
                if (baseInfo != null && baseInfo.getBatchId() != null && baseInfo.getBatchId() > 0) {
                    DeviceObdExFactoryBatchInfo batchInfo = deviceObdExFactoryBatchInfoService.getById(baseInfo.getBatchId());
                    if (batchInfo == null || batchInfo.getExFactory() == 0) {
                        throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                    }
                    //查询的日期为出厂前的
                    if (DateUtils.compareTwoTimeBefore(DateUtils.parseStrToDate(dto.getTime(), DateUtils.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI_SS), batchInfo.getExDate())) {
                        throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
                    }
                }
            }
            try {
                GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();//EntityConversionUtil.copy(dto, GetDevicePcbGpsInfoDO.class);
                getDeviceObdGpsInfoDO.setDtu(dto.getDtu());
                String tableName = "device_obd_gps_info_";
                String startTime = dto.getTime() + " 00:00：00";
                String endTime = dto.getTime() + " 23:59:59";
//            getDeviceObdGpsInfoDO.setPage(dto.getPage());
//            getDeviceObdGpsInfoDO.setPageSize(dto.getPageSize());
                getDeviceObdGpsInfoDO.setSTime(startTime);
                getDeviceObdGpsInfoDO.setETime(endTime);
                tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
                getDeviceObdGpsInfoDO.setSortRow("time");
                getDeviceObdGpsInfoDO.setSortOrder("asc");
                getDeviceObdGpsInfoDO.setTableName(tableName);
                List<DeviceObdGpsInfo> tempList = deviceObdGpsInfoService.getAllList(getDeviceObdGpsInfoDO);
                if (tempList != null && tempList.size() > 0) {
                    gpsList.addAll(tempList);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
//            PageInfo<DeviceObdGpsInfo> pageInfo = new PageInfo<>(gpsList);
//            PageResult<List<GetTrackInfoListVO>> build = PageResult.<List<GetTrackInfoListVO>>builder().result(trackList).pageInfo(pageInfo).build();
//            vo.setTotalNum(build.getTotal());
//            vo.setTotalPage(build.getPageCount());
        }
        if (gpsList.size() > 0) {
            gpsList.forEach(item -> {
                GetTrackInfoListVO getTrackInfoListVO = EntityConversionUtil.copy(item, GetTrackInfoListVO.class);
                getTrackInfoListVO.setC(item.getColorIndex() == null ? 0 : Integer.parseInt(item.getColorIndex()));
                trackList.add(getTrackInfoListVO);
            });
        }
        vo.setTrackList(trackList);
        return vo;
    }

    /**
     * 获取安卓版设备轨迹
     *
     * @param dto
     * @return GetTrackInfoVO
     * @author tm
     * @date 2023-06-08 22:02
     */
    private GetTrackInfoVO getPcbTrackInfo(GetTrackInfoDTO dto) {
        GetTrackInfoVO vo = new GetTrackInfoVO();
        List<String> colors = getColorList();
        vo.setColors(colors);
        List<DevicePcbGpsInfo> gpsList = new ArrayList<>();
        List<GetTrackInfoListVO> trackList = new ArrayList<>();
        GetDevicePcbGpsInfoDO getDevicePcbGpsInfoDO = new GetDevicePcbGpsInfoDO();//EntityConversionUtil.copy(dto, GetDevicePcbGpsInfoDO.class);
        if (dto.getDtu().indexOf("-") > -1) {
            String shortDtu = dto.getDtu().split("-")[1];
            getDevicePcbGpsInfoDO.setShortDtu(shortDtu);
        } else if (dto.getDtu().indexOf("=") > -1) {
            String shortDtu = dto.getDtu().split("=")[1];
            getDevicePcbGpsInfoDO.setShortDtu(shortDtu);
        } else {
            getDevicePcbGpsInfoDO.setDtu(dto.getDtu());
        }
        LoginUserDetails loginUserDetails = SecurityUtils.getLoginUser();
        System.out.println("====="+loginUserDetails);
        if (loginUserDetails!=null &&loginUserDetails.getUser()!=null && loginUserDetails.getUser().getUserType()!=null && loginUserDetails.getUser().getUserType() != Constants.SysUserUserType.TYPE_管理员 && loginUserDetails.getUser().getUserType() != Constants.SysUserUserType.TYPE_车间生产) {
            List<String> shortDtuList = new ArrayList<>();
            shortDtuList.add("0");
            GetDevicePcbBaseInfoDO getDevicePcbBaseInfoDO = new GetDevicePcbBaseInfoDO();
            getDevicePcbBaseInfoDO.setFactoryUserId(loginUserDetails.getUser().getUserId());
            getDevicePcbBaseInfoDO.setSortRow("id");
            List<DevicePcbBaseInfo> baseList = devicePcbBaseInfoService.getAllList(getDevicePcbBaseInfoDO);
            if (baseList != null && baseList.size() > 0) {
                shortDtuList = baseList.stream().map(DevicePcbBaseInfo::getShortDtu).collect(Collectors.toList());
            }
            getDevicePcbGpsInfoDO.setShortDtus(shortDtuList);
        }
        try {
            if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
                String startTime = dto.getStartTime();
                String endTime = dto.getEndTime();
                boolean flag = true;
                Date startDate = DateUtils.parseStrToDate(startTime, DateUtils.YYYY_MM_DD_HH_MM_SS);
                Date endDate = DateUtils.parseStrToDate(endTime, DateUtils.YYYY_MM_DD_HH_MM_SS);
                while (flag) {
                    System.out.println("startDate :" + startDate);
                    System.out.println("endDate :" + endDate);
                    if (DateUtils.compareIsSameDay(startDate, endDate)) {
                        String tableName = "device_pcb_gps_info_" + DateUtils.parseDateToStr(DateUtils.YYYYMMDD, startDate);
                        getDevicePcbGpsInfoDO.setSTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate));
                        getDevicePcbGpsInfoDO.setETime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endDate));
                        getDevicePcbGpsInfoDO.setSortRow("time");
                        getDevicePcbGpsInfoDO.setSortOrder("asc");
                        getDevicePcbGpsInfoDO.setTableName(tableName);
                        List<DevicePcbGpsInfo> tempList = devicePcbGpsInfoService.getAllList(getDevicePcbGpsInfoDO);
                        if (tempList != null && tempList.size() > 0) {
                            gpsList.addAll(tempList);
                        }
                        flag = false;
                    } else {
                        String tableName = "device_pcb_gps_info_" + DateUtils.parseDateToStr(DateUtils.YYYYMMDD, startDate);
                        String eTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startDate) + " 23:59:59";
                        getDevicePcbGpsInfoDO.setSTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate));
                        getDevicePcbGpsInfoDO.setETime(eTime);
                        getDevicePcbGpsInfoDO.setSortRow("time");
                        getDevicePcbGpsInfoDO.setSortOrder("asc");
                        getDevicePcbGpsInfoDO.setTableName(tableName);
                        List<DevicePcbGpsInfo> tempList = devicePcbGpsInfoService.getAllList(getDevicePcbGpsInfoDO);
                        if (tempList != null && tempList.size() > 0) {
                            gpsList.addAll(tempList);
                        }
                        String tempStartDate = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(startDate, 1)) + " 00:00:00";
                        startDate = DateUtils.parseStrToDate(tempStartDate, DateUtils.YYYY_MM_DD_HH_MM_SS);
                    }
                }
            } else if (StringUtils.isNotBlank(dto.getTime())) {
                String tableName = "device_pcb_gps_info_";
                String startTime = dto.getTime() + " 00:00：00";
                String endTime = dto.getTime() + " 23:59:59";
                getDevicePcbGpsInfoDO.setPage(dto.getPage());
                getDevicePcbGpsInfoDO.setPageSize(dto.getPageSize());
                getDevicePcbGpsInfoDO.setSTime(startTime);
                getDevicePcbGpsInfoDO.setETime(endTime);
                tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
                getDevicePcbGpsInfoDO.setSortRow("time");
                getDevicePcbGpsInfoDO.setSortOrder("asc");
                getDevicePcbGpsInfoDO.setTableName(tableName);
                List<DevicePcbGpsInfo> tempList = devicePcbGpsInfoService.getAllList(getDevicePcbGpsInfoDO);
                if (tempList != null && tempList.size() > 0) {
                    gpsList.addAll(gpsList);
                }
//            PageInfo<DevicePcbGpsInfo> pageInfo = new PageInfo<>(gpsList);
//            PageResult<List<GetTrackInfoListVO>> build = PageResult.<List<GetTrackInfoListVO>>builder().result(trackList).pageInfo(pageInfo).build();
//            vo.setTotalNum(build.getTotal());
//            vo.setTotalPage(build.getPageCount());
//            vo.setTrackList(build.getResult());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (gpsList != null && gpsList.size() > 0) {
            int i = 0;
            for (DevicePcbGpsInfo item : gpsList) {
                GetTrackInfoListVO getTrackInfoListVO = EntityConversionUtil.copy(item, GetTrackInfoListVO.class);
                getTrackInfoListVO.setC(Integer.valueOf(item.getColorIndex()));
                if (Integer.valueOf(item.getIsWork()) < 100)
                    getTrackInfoListVO.setIsWork("0000");
                else getTrackInfoListVO.setIsWork("0001");
                String lon = item.getLon();
                /*Double dLon = Double.parseDouble(lon);
                if(i%2==0){
                    dLon+=0.000005d;
                }else{
                    dLon-=0.000005d;
                }
                lon = dLon.toString();*/
                String lat = item.getLat();
                if (lon.length() > 10) {
                    getTrackInfoListVO.setLon(lon.substring(0, 10));
                } else {
                    getTrackInfoListVO.setLon(lon);
                }
                if (lat.length() > 10) {
                    getTrackInfoListVO.setLat(lat.substring(0, 10));
                } else {
                    getTrackInfoListVO.setLat(lat);
                }
                System.out.println("+++++++++++++++++++++++长度： " + trackList.size());
                trackList.add(getTrackInfoListVO);
                i++;
            }
        }
        vo.setTrackList(trackList);
        return vo;
    }

    /**
     * 获取PCB设备图片信息
     *
     * @param dto
     * @return GetImgInfoVO
     * @author tm
     * @date 2023-06-09 13:35
     */
    public GetImgInfoVO getPcbImgInfo(GetImgInfoDTO dto) {
        GetImgInfoVO vo = new GetImgInfoVO();
        GetDevicePcbGpsImgInfoDO getDevicePcbGpsImgInfoDO = EntityConversionUtil.copy(dto, GetDevicePcbGpsImgInfoDO.class);
        String tableName = "device_pcb_gps_img_info_";
        String startTime = null;
        String endTime = null;
        if (dto.getTime() != null && !"".equals(dto.getTime())) {
//            getDevicePcbGpsInfoDO.setStartTime(LocalDate.parse(dto.getTime()+" 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            getDevicePcbGpsInfoDO.setEndTime(LocalDate.parse(dto.getTime()+" 23:59:59",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            startTime = dto.getTime() + " 00:00:00";
            endTime = dto.getTime() + " 23:59:59";
            getDevicePcbGpsImgInfoDO.setSTime(startTime);
            getDevicePcbGpsImgInfoDO.setETime(endTime);
            tableName += dto.getTime().replaceAll("-", "");
        } else if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
            getDevicePcbGpsImgInfoDO.setSTime(dto.getStartTime());
            getDevicePcbGpsImgInfoDO.setETime(dto.getEndTime());
        }
        if (getDevicePcbGpsImgInfoDO.getShortDtu() != null && !"".equals(getDevicePcbGpsImgInfoDO.getShortDtu())) {
            String shortDtu = getDevicePcbGpsImgInfoDO.getShortDtu();
            if (shortDtu.length() > 5) {
                shortDtu = shortDtu.substring(shortDtu.length() - 5, shortDtu.length());
            }
            getDevicePcbGpsImgInfoDO.setShortDtu(shortDtu);
        }
        LoginUserDetails loginUserDetails = SecurityUtils.getLoginUser();
        SysUser sysUser = loginUserDetails.getUser();
        if (sysUser.getUserType() != Constants.SysUserUserType.TYPE_管理员 && sysUser.getUserType() != Constants.SysUserUserType.TYPE_车间生产) {
            List<String> shortDtuList = new ArrayList<>();
            shortDtuList.add("0");
            GetDevicePcbBaseInfoDO getDevicePcbBaseInfoDO = new GetDevicePcbBaseInfoDO();
            getDevicePcbBaseInfoDO.setFactoryUserId(sysUser.getUserId());
            getDevicePcbBaseInfoDO.setSortRow("id");
            List<DevicePcbBaseInfo> baseList = devicePcbBaseInfoService.getAllList(getDevicePcbBaseInfoDO);
            if (baseList != null && baseList.size() > 0) {
                shortDtuList = baseList.stream().map(DevicePcbBaseInfo::getShortDtu).collect(Collectors.toList());
            }
            getDevicePcbGpsImgInfoDO.setShortDtus(shortDtuList);
        }
        getDevicePcbGpsImgInfoDO.setSortRow("time");
        getDevicePcbGpsImgInfoDO.setSortOrder("desc");
        getDevicePcbGpsImgInfoDO.setTableName(tableName);
        List<GetImgInfoListVO> imgList = new ArrayList<>();
        List<DevicePcbGpsImgInfo> gpsList = new ArrayList<>();
        try {
            gpsList = devicePcbGpsImgInfoService.getPageList(getDevicePcbGpsImgInfoDO);
            if (gpsList != null && gpsList.size() > 0) {
                gpsList.forEach(item -> {
                    GetImgInfoListVO imgVo = EntityConversionUtil.copy(item, GetImgInfoListVO.class);
                    String imgUrl = "";
                    if (item.getImgSrc() != null && !"".equals(item.getImgSrc())) {
                        imgUrl = item.getImgSrc();
//                    imgVo.setImgUrl("http://39.108.117.16:8866" + item.getImgSrc());
                    }
                    if (StringUtils.isNotBlank(imgUrl) && !imgUrl.startsWith("http")) {
                        imgUrl = "http://39.108.117.16:8866" + imgUrl;
                    }
                    imgVo.setImgUrl(imgUrl);
                    imgList.add(imgVo);
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        vo.setImgList(imgList);
        PageInfo<DevicePcbGpsImgInfo> pageInfo = new PageInfo<>(gpsList);
        PageResult<List<GetImgInfoListVO>> build = PageResult.<List<GetImgInfoListVO>>builder().result(imgList).pageInfo(pageInfo).build();
        vo.setTotalNum(build.getTotal());
        vo.setTotalPage(build.getPageCount());
        return vo;
    }


    public GetImgInfoVO getPmdImgInfo(GetImgInfoDTO dto) {
        GetImgInfoVO vo = new GetImgInfoVO();
        try {
            GetDevicePmdGpsImgInfoDO getDevicePmdGpsImgInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdGpsImgInfoDO.class);
            String tableName = "device_pmd_gps_img_info_";
            String startTime = null;
            String endTime = null;
            LoginUserDetails loginUserDetails = SecurityUtils.getLoginUser();
            if (loginUserDetails != null && loginUserDetails.getUser() != null && loginUserDetails.getUser().getUserType() != null) {
                SysUser sysUser = loginUserDetails.getUser();
                if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机生产厂家 || sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机经销商) {
                    List<String> dtus = new ArrayList<>();
                    dtus.add("0");
                    GetDevicePmdBaseInfoDO getDevicePmdBaseInfoDO = new GetDevicePmdBaseInfoDO();
                    if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机生产厂家) {
                        getDevicePmdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                    } else if (sysUser.getUserType() == Constants.SysUserUserType.TYPE_播种机经销商) {
                        List<Long> factoryUserIds = new ArrayList<>();
                        factoryUserIds.add(0l);
                        GetUserInfoDO getUserInfoDO = new GetUserInfoDO();
                        getUserInfoDO.setUserType(1);
                        getUserInfoDO.setDeviceType(3);
                        getUserInfoDO.setSortRow("id");
                        List<UserInfo> userList = userInfoService.getAllList(getUserInfoDO);
                        if (userList != null && userList.size() > 0) {
                            factoryUserIds = userList.stream().map(UserInfo::getId).collect(Collectors.toList());
                        }
                        getDevicePmdBaseInfoDO.setFactoryUserIds(factoryUserIds);
                    }
                    getDevicePmdBaseInfoDO.setSortRow("id");
                    List<DevicePmdBaseInfo> baseList = devicePmdBaseInfoService.getAllList(getDevicePmdBaseInfoDO);
                    if (baseList != null && baseList.size() > 0) {
                        dtus = baseList.stream().map(DevicePmdBaseInfo::getDtu).collect(Collectors.toList());
                    }
                    getDevicePmdGpsImgInfoDO.setDtus(dtus);
                }
            }
            if (dto.getTime() != null && !"".equals(dto.getTime())) {
//            getDevicePcbGpsInfoDO.setStartTime(LocalDate.parse(dto.getTime()+" 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            getDevicePcbGpsInfoDO.setEndTime(LocalDate.parse(dto.getTime()+" 23:59:59",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                startTime = dto.getTime() + " 00:00:00";
                endTime = dto.getTime() + " 23:59:59";
                getDevicePmdGpsImgInfoDO.setSTime(startTime);
                getDevicePmdGpsImgInfoDO.setETime(endTime);
                tableName += dto.getTime().replaceAll("-", "");
            } else if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
                getDevicePmdGpsImgInfoDO.setSTime(dto.getStartTime());
                getDevicePmdGpsImgInfoDO.setETime(dto.getEndTime());
            }
            getDevicePmdGpsImgInfoDO.setSortRow("time");
            getDevicePmdGpsImgInfoDO.setSortOrder("desc");
            getDevicePmdGpsImgInfoDO.setTableName(tableName);
            List<GetImgInfoListVO> imgList = new ArrayList<>();
            List<DevicePmdGpsImgInfo> gpsList = devicePmdGpsImgInfoService.getPageList(getDevicePmdGpsImgInfoDO);
            if (gpsList != null && gpsList.size() > 0) {
                gpsList.forEach(item -> {
                    GetImgInfoListVO imgVo = EntityConversionUtil.copy(item, GetImgInfoListVO.class);
                    String imgUrl = "";
                    if (item.getImgSrc() != null && !"".equals(item.getImgSrc())) {
                        imgVo.setImgUrl(item.getImgSrc());
                    }
                    imgList.add(imgVo);
                });
            }
            vo.setImgList(imgList);
            PageInfo<DevicePmdGpsImgInfo> pageInfo = new PageInfo<>(gpsList);
            PageResult<List<GetImgInfoListVO>> build = PageResult.<List<GetImgInfoListVO>>builder().result(imgList).pageInfo(pageInfo).build();
            vo.setTotalNum(build.getTotal());
            vo.setTotalPage(build.getPageCount());
        } catch (Exception e) {
            e.printStackTrace();
            vo.setTotalNum(0l);
            vo.setTotalPage(0);
            vo.setImgList(new ArrayList<GetImgInfoListVO>());
        }
        return vo;
    }

    public GetErrorImgInfoVO getPcbErrorImgInfo(GetErrorImgInfoDTO dto) {
        GetErrorImgInfoVO vo = new GetErrorImgInfoVO();
        GetDevicePcbGpsImgInfoDO getDevicePcbGpsImgInfoDO = EntityConversionUtil.copy(dto, GetDevicePcbGpsImgInfoDO.class);
        getDevicePcbGpsImgInfoDO.setImgPosition(null);
        String tableName = "device_pcb_gps_img_info_";
        String startTime = null;
        String endTime = null;
        if (dto.getTime() != null && !"".equals(dto.getTime())) {
//            getDevicePcbGpsInfoDO.setStartTime(LocalDate.parse(dto.getTime()+" 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            getDevicePcbGpsInfoDO.setEndTime(LocalDate.parse(dto.getTime()+" 23:59:59",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            startTime = dto.getTime() + " 00:00:00";
            endTime = dto.getTime() + " 23:59:59";
            getDevicePcbGpsImgInfoDO.setSTime(startTime);
            getDevicePcbGpsImgInfoDO.setETime(endTime);
            tableName += dto.getTime().replaceAll("-", "");
        } else if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
            getDevicePcbGpsImgInfoDO.setSTime(dto.getStartTime());
            getDevicePcbGpsImgInfoDO.setETime(dto.getEndTime());
        }
        if (getDevicePcbGpsImgInfoDO.getShortDtu() != null && !"".equals(getDevicePcbGpsImgInfoDO.getShortDtu())) {
            String shortDtu = getDevicePcbGpsImgInfoDO.getShortDtu();
            if (shortDtu.length() > 5) {
                shortDtu = shortDtu.substring(shortDtu.length() - 5, shortDtu.length());
            }
            getDevicePcbGpsImgInfoDO.setShortDtu(shortDtu);
        }
        getDevicePcbGpsImgInfoDO.setSortRow("time");
        getDevicePcbGpsImgInfoDO.setSortOrder("desc");
        getDevicePcbGpsImgInfoDO.setContent("VDERROR" + dto.getImgPosition());
        getDevicePcbGpsImgInfoDO.setTableName(tableName);
        List<GetErrorImgInfoListVO> imgList = new ArrayList<>();
        List<DevicePcbGpsImgInfo> gpsList = new ArrayList<>();
        try {
            gpsList = devicePcbGpsImgInfoService.getPageList(getDevicePcbGpsImgInfoDO);
            if (gpsList != null && gpsList.size() > 0) {
                gpsList.forEach(item -> {
                    GetErrorImgInfoListVO imgVo = EntityConversionUtil.copy(item, GetErrorImgInfoListVO.class);
                    String imgPosition = "";
                    if (item.getContent().indexOf("VDERROR1") > -1) {
                        imgPosition = "1";
                    } else if (item.getContent().indexOf("VDERROR2") > -1) {
                        imgPosition = "2";
                    }
                    imgVo.setImgPosition(imgPosition);
                    imgList.add(imgVo);
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        vo.setImgList(imgList);
        PageInfo<DevicePcbGpsImgInfo> pageInfo = new PageInfo<>(gpsList);
        PageResult<List<GetErrorImgInfoListVO>> build = PageResult.<List<GetErrorImgInfoListVO>>builder().result(imgList).pageInfo(pageInfo).build();
        vo.setTotalNum(build.getTotal());
        vo.setTotalPage(build.getPageCount());
        return vo;
    }

    /**
     * 获取播种机设备轨迹
     *
     * @param dto
     * @return GetTrackInfoVO
     * @author tm
     * @date 2023-06-08 22:02
     */
    private GetTrackInfoVO getPmdTrackInfo(GetTrackInfoDTO dto) {
        GetTrackInfoVO vo = new GetTrackInfoVO();
        List<String> colors = getColorList();
        vo.setColors(colors);
        try {
            GetDevicePmdGpsInfoDO getDevicePmdGpsInfoDO = new GetDevicePmdGpsInfoDO();//EntityConversionUtil.copy(dto, GetDevicePcbGpsInfoDO.class);
            getDevicePmdGpsInfoDO.setDtu(dto.getDtu());
            String tableName = "device_pmd_gps_info_";
            String startTime = dto.getTime() + " 00:00：00";
            String endTime = dto.getTime() + " 23:59:59";
            getDevicePmdGpsInfoDO.setPage(dto.getPage());
            getDevicePmdGpsInfoDO.setPageSize(dto.getPageSize());
            getDevicePmdGpsInfoDO.setSTime(startTime);
            getDevicePmdGpsInfoDO.setETime(endTime);
            tableName += dto.getTime().split(" ")[0].replaceAll("-", "");
            getDevicePmdGpsInfoDO.setSortRow("time");
            getDevicePmdGpsInfoDO.setSortOrder("asc");
            getDevicePmdGpsInfoDO.setTableName(tableName);
            List<GetTrackInfoListVO> trackList = new ArrayList<>();
            List<DevicePmdGpsInfo> gpsList = devicePmdGpsInfoService.getPageList(getDevicePmdGpsInfoDO);
            if (gpsList != null && gpsList.size() > 0) {
                gpsList.forEach(item -> {
                    GetTrackInfoListVO getTrackInfoListVO = EntityConversionUtil.copy(item, GetTrackInfoListVO.class);
                    getTrackInfoListVO.setC(item.getColorIndex() == null ? 0 : Integer.valueOf(item.getColorIndex()));
                    String lat = item.getLat();
                    String lon = item.getLon();
                    if (lon.length() > 10) {
                        getTrackInfoListVO.setLon(lon.substring(0, 10));
                    } else {
                        getTrackInfoListVO.setLon(lon);
                    }
                    if (lat.length() > 10) {
                        getTrackInfoListVO.setLat(lat.substring(0, 10));
                    } else {
                        getTrackInfoListVO.setLat(lat);
                    }
                    trackList.add(getTrackInfoListVO);
                });
            }
            PageInfo<DevicePmdGpsInfo> pageInfo = new PageInfo<>(gpsList);
            PageResult<List<GetTrackInfoListVO>> build = PageResult.<List<GetTrackInfoListVO>>builder().result(trackList).pageInfo(pageInfo).build();
            vo.setTotalNum(build.getTotal());
            vo.setTotalPage(build.getPageCount());
            vo.setTrackList(build.getResult());
        } catch (Exception e) {
            vo.setTotalNum(0l);
            vo.setTotalPage(0);
            vo.setTrackList(new ArrayList<GetTrackInfoListVO>());
        }
        return vo;
    }

    @Log(title = "设备管理-获取设备作业日报信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "获取设备作业日报信息")
    @PostMapping("/getWorkDailyInfo")
    public Result<PageResult<List<GetWorkDailyInfoVO>>> getWorkDailyInfo(@RequestBody @Valid GetWorkDailyInfoDTO dto) {
        List<GetWorkDailyInfoVO> voList = new ArrayList<>();
        int type = dto.getType();
        if (type == 1) {//OBD
            GetDeviceObdWorkDailyRecordInfoDO getDeviceObdWorkDailyRecordInfoDO = EntityConversionUtil.copy(dto, GetDeviceObdWorkDailyRecordInfoDO.class);
            List<DeviceObdWorkDailyRecordInfo> recordList = deviceObdWorkDailyRecordInfoService.getPageList(getDeviceObdWorkDailyRecordInfoDO);
            if (recordList != null && recordList.size() > 0) {
                for (DeviceObdWorkDailyRecordInfo info : recordList) {
                    GetWorkDailyInfoVO vo = EntityConversionUtil.copy(info, GetWorkDailyInfoVO.class);
                    vo.setWorkDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, info.getWorkDate()));
                    voList.add(vo);
                }
                PageInfo<DeviceObdWorkDailyRecordInfo> pageInfo = new PageInfo<>(recordList);
                PageResult<List<GetWorkDailyInfoVO>> build = PageResult.<List<GetWorkDailyInfoVO>>builder().result(voList).pageInfo(pageInfo).build();
                return Result.suc(build);
            }
        } else if (type == 2) {//PCB
            GetDevicePcbWorkDailyRecordInfoDO getDevicePcbWorkDailyRecordInfoDO = EntityConversionUtil.copy(dto, GetDevicePcbWorkDailyRecordInfoDO.class);
            List<DevicePcbWorkDailyRecordInfo> recordList = devicePcbWorkDailyRecordInfoService.getPageList(getDevicePcbWorkDailyRecordInfoDO);
            if (recordList != null && recordList.size() > 0) {
                for (DevicePcbWorkDailyRecordInfo info : recordList) {
                    GetWorkDailyInfoVO vo = EntityConversionUtil.copy(info, GetWorkDailyInfoVO.class);
                    vo.setWorkDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, info.getWorkDate()));
                    voList.add(vo);
                }
                PageInfo<DevicePcbWorkDailyRecordInfo> pageInfo = new PageInfo<>(recordList);
                PageResult<List<GetWorkDailyInfoVO>> build = PageResult.<List<GetWorkDailyInfoVO>>builder().result(voList).pageInfo(pageInfo).build();
                return Result.suc(build);
            }
        } else if (type == 3) {//PMD
            GetDevicePmdWorkDailyRecordInfoDO getDevicePmdWorkDailyRecordInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdWorkDailyRecordInfoDO.class);
            List<DevicePmdWorkDailyRecordInfo> recordList = devicePmdWorkDailyRecordInfoService.getPageList(getDevicePmdWorkDailyRecordInfoDO);
            if (recordList != null && recordList.size() > 0) {
                for (DevicePmdWorkDailyRecordInfo info : recordList) {
                    GetWorkDailyInfoVO vo = EntityConversionUtil.copy(info, GetWorkDailyInfoVO.class);
                    vo.setWorkDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, info.getWorkDate()));
                    voList.add(vo);
                }
                PageInfo<DevicePmdWorkDailyRecordInfo> pageInfo = new PageInfo<>(recordList);
                PageResult<List<GetWorkDailyInfoVO>> build = PageResult.<List<GetWorkDailyInfoVO>>builder().result(voList).pageInfo(pageInfo).build();
                return Result.suc(build);
            }
        }
        List<DevicePmdWorkDailyRecordInfo> recordList = new ArrayList<>();
        PageInfo<DevicePmdWorkDailyRecordInfo> pageInfo = new PageInfo<>(recordList);
        PageResult<List<GetWorkDailyInfoVO>> build = PageResult.<List<GetWorkDailyInfoVO>>builder().result(voList).pageInfo(pageInfo).build();
        return Result.suc(build);
    }

    @Log(title = "设备管理-测试python", businessType = BusinessType.INSERT)
    @ApiOperation(value = "测试python")
    @GetMapping("/testPython")
    public Result<Objects> testPython(@RequestParam String time) {
        try {
            Date date = DateUtils.parseStrToDate(time, DateUtils.DATE_FORMAT_YYYY_MM);
            int month = Integer.parseInt(DateUtils.getMonth(date));
            boolean flag = true;
            Date startDate = DateUtils.parseStrToDate(time + "-01", DateUtils.DATE_FORMAT_YYYY_MM_DD);
            while (flag) {
                try {
                    String t = DateUtils.parseDateToStr(startDate, DateUtils.DATE_FORMAT_YYYYMMDD);
                    System.out.println("-------------当前计算日期：" + t);
                    PythonUtils.callNanSha(t, null, null);
                    String filePath = "d:/test/area/" + time + ".txt";
                    FileUtils.writeFile(DateUtils.parseDateToStr(startDate, DateUtils.DATE_FORMAT_YYYY_MM_DD), filePath);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                startDate = DateUtils.addDate(startDate, 0, 0, 1, 0, 0, 0, 0);
                if (month != Integer.parseInt(DateUtils.getMonth(startDate))) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.suc();
    }

    private List<String> getColorList() {
        List<String> colors = new ArrayList<>();
        colors.add("007940");//绿色 工作中
        colors.add("CDCAAE");//灰色 未工作中
        colors.add("f00");//红色
        return colors;
    }

    @Log(title = "设备管理-计算老数据轨迹红点情况", businessType = BusinessType.INSERT)
    @ApiOperation(value = "计算老数据轨迹红点情况")
    @GetMapping("/calOldObdData")
    public Result<Objects> calOldObdData() {
        System.out.println("=========计算开始");
        log.info("==============计算开始");
        Date date = DateUtils.parseStrToDate("2023-06-09", DateUtils.DATE_FORMAT_YYYY_MM_DD);
        try {
            Date lastDate = DateUtils.parseStrToDate("2022-09-06", DateUtils.DATE_FORMAT_YYYY_MM_DD);
            boolean flag = true;
            while (flag) {
                List<DeviceObdDayInfo> dayList = new ArrayList<>();
                String tableName = "device_obd_gps_info_";
                date = DateUtils.addDays(date, -1);
                System.out.println("=========================date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                log.info("========================= 数据date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                int year = Integer.parseInt(DateUtils.getYear(date));
                int month = Integer.parseInt(DateUtils.getMonth(date));
                int day = Integer.parseInt(DateUtils.getDate(date));
                String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                dayStr = dayStr.replaceAll("-", "");
                GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
                List<Map<String, Object>> list = deviceObdGpsInfoService.getListGroupBy(getDeviceObdGpsInfoDO);
                if (list != null && list.size() > 0) {
                    list.forEach(item -> {
                        String dtu = (String) item.get("dtu");
                        if (dtu.length() == 13) {
                            System.out.println("=======================设备dtu :" + dtu);
                            log.info("=======================设备dtu :" + dtu);
                            DeviceObdDayInfo dayInfo = new DeviceObdDayInfo();
                            dayInfo.setDtu(dtu);
                            dayInfo.setYear(year);
                            dayInfo.setMonth(month);
                            dayInfo.setDay(day);
                            dayInfo.setCreatedTime(new Date());
                            dayList.add(dayInfo);
                        }
                    });
                }

                if (dayList != null && dayList.size() > 0) {
                    deviceObdDayInfoService.saveList(dayList);
                }
                if (DateUtils.compareIsSameDay(date, lastDate)) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("统计错误日志： " + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
        }
        log.info("==============计算结束");
        return Result.suc();
    }

    @Log(title = "设备管理-统计OBD工况信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "统计OBD工况信息")
    @GetMapping("/testStatisticsObdGkInfo")
    public Result<Objects> testStatisticsObdGkInfo() {
        Date date = DateUtils.parseStrToDate("2023-10-28", DateUtils.DATE_FORMAT_YYYY_MM_DD);
        try {
            Date lastDate = DateUtils.parseStrToDate("2023-09-01", DateUtils.DATE_FORMAT_YYYY_MM_DD);
            boolean flag = true;
            while (flag) {
                List<DeviceObdGkDayInfo> dayList = new ArrayList<>();
                String tableName = "device_25_obd_info_";
                date = DateUtils.addDays(date, -1);
                System.out.println("=========================date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                log.info("========================= 数据date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                int year = Integer.parseInt(DateUtils.getYear(date));
                int month = Integer.parseInt(DateUtils.getMonth(date));
                int day = Integer.parseInt(DateUtils.getDate(date));
                String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                dayStr = dayStr.replaceAll("-", "");
                GetDevice25ObdInfoDO getDevice25ObdInfoDO = new GetDevice25ObdInfoDO();
                getDevice25ObdInfoDO.setTableName(tableName + dayStr);
                List<Map<String, Object>> list = device25ObdInfoService.getListGroupBy(getDevice25ObdInfoDO);
                if (list != null && list.size() > 0) {
                    for (Map<String, Object> item : list) {
                        String dtu = (String) item.get("dtu");
                        if (dtu.length() == 13) {
                            System.out.println(DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + "=======================设备dtu :" + dtu);
                            log.info(DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + "=======================设备dtu :" + dtu);
                            getDevice25ObdInfoDO.setDtu(dtu);
                            getDevice25ObdInfoDO.setSortRow("createTime");
                            getDevice25ObdInfoDO.setSortOrder("desc");
                            List<Device25ObdInfo> gkList = device25ObdInfoService.getAllList(getDevice25ObdInfoDO);
                            Device25ObdInfo gk = gkList.get(0);
                            DeviceObdGkDayInfo dayInfo = new DeviceObdGkDayInfo();
                            dayInfo.setDtu(dtu);
                            dayInfo.setYear(year);
                            dayInfo.setMonth(month);
                            dayInfo.setDay(day);
                            dayInfo.setLastFdjzs(gk.getFdjzs());
                            dayInfo.setLastDcdy(gk.getDcdy());
                            boolean status = calObdGkStatus(gkList);
                            if (status) dayInfo.setStatus(1);
                            else dayInfo.setStatus(0);
                            dayInfo.setCreatedTime(new Date());
                            dayList.add(dayInfo);
                        }
                    }
                }

                if (dayList != null && dayList.size() > 0) {
                    deviceObdGkDayInfoService.saveList(dayList);
                }
                if (DateUtils.compareIsSameDay(date, lastDate)) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("统计错误日志： " + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
        }
        log.info("==============统计结束");
        return Result.suc();
    }

    private boolean calObdGkStatus(List<Device25ObdInfo> gkList) {
        boolean flag = false;
        for (Device25ObdInfo info : gkList) {
            String fdjzs = info.getFdjzs();
            String dcdy = info.getDcdy();
            if (!"".equals(dcdy) && !"0".equals(fdjzs) && !"".equals(dcdy) && !"0.0".equals(dcdy)) {
                flag = true;
                break;
            }
        }
        return flag;
    }


    @Log(title = "设备管理-统计OBDTCP信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "统计OBDTCP信息")
    @GetMapping("/testStatisticsObdTCPInfo")
    public Result<Objects> testStatisticsObdTCPInfo() {
        //1928台中定位异常数据
        /*String str = "02ai990000024,02ai990000075,02ai990000077,02ai990000087,02ai990000106,02ai990000137,02ai990000138,02ai990000141,02ai990000146,02ai990000155,02ai990000174,02ai990000188,02ai990000202,02ai990000215,02ai990000269,02ai990000302,02ai990000307,02ai990000310,02ai990000316,02ai990000323,02ai990000354,02ai990000408,02ai990000418,02ai990000513,02ai990000557,02ai990000573,02ai990000587,02ai990000599,02ai990000631,02ai990000633,02ai990000693,02ai990000699,02ai990000707,02ai990000733,02ai990000736,02ai990000754,02ai990000764,02ai990000778,02ai990000812,02ai990000831,02ai990000863,02ai990000874,02ai990000875,02ai990000889,02ai990000892,02ai990000979,02ai990001029,02ai990001041,02ai990001050,02ai990001053,02ai990001062,02ai990001075,02ai990001097,02ai990001112,02ai990001152,02ai990001181,02ai990001196,02ai990001222,02ai990001251,02ai990001254,02ai990001255,02ai990001289,02ai990001324,02ai990001344,02ai990001366,02ai990001385,02ai990001409,02ai990001498,02ai990001500,02ai990001507,02ai990001565,02ai990001615,02ai990001626,02ai990001629,02ai990001644,02ai990001727,02ai990001730,02ai990001734,02ai990001746,02ai990001812,02ai990001835,02ai990001854,02ai990001876,02ai990001886,02ai990001888,02ai990001895,02ai990001903,02ai990001908,02ai990001920,02ai990001955,02ai990001980,02ai990002014,02ai990002025,02ai990002040,02ai990002056,02ai990002090,02ai990002096,02ai990002101,02ai990002161,02ai990002163,02ai990002185,02ai990002187,02ai990002216,02ai990002218,02ai990002238,02ai990002249,02ai990002264,02ai990002320,02ai990002327,02ai990002338,02ai990002356,02ai990002379,02ai990002390,02ai990002413,02ai990002427,02ai990002432,02ai990002452,02ai990002502,02ai990002521,02ai990002567,02ai990002576,02ai990002624,02ai990002632,02ai990002703,02ai990002755,02ai990002792,02ai990002828,02ai990002876,02ai990002887,02ai990002897,02ai990002918,02ai990002938,02ai990002985,02ai990003020,02ai990003030,02ai990003033,02ai990003071,02ai990003098,02ai990003124,02ai990003166,02ai990003194,02ai990003204,02ai990003207,02ai990003277,02ai990003283,02ai990003314,02ai990003326,02ai990003382,02ai990003434,02ai990003463,02ai990003480,02ai990003688,02ai990003752,02ai990003808,02ai990003828,02ai990003927,02ai990003961,02ai990003964,02ai990003977,02ai990003990,02ai990003993,02ai990004010,02ai990004103,02ai990004107,02ai990004135,02ai990004169,02ai990004193,02ai990004197,02ai990004243,02ai990004304,02ai990004336,02ai990004380,02ai990004396,02ai990004412,02ai990004437,02ai990004474,02ai990004496,02ai990004505,02ai990004509,02ai990004534,02ai990004558,02ai990004596,02ai990004601,02ai990004608,02ai990004666,02ai990004683,02ai990004697,02ai990004702,02ai990004724,02ai990004753,02ai990004759,02ai990004794,02ai990004840,02ai990004864,02ai990004873,02ai990004874,02ai990004880,02ai990004897,02ai990004903,02ai990004910,02ai990004915,02ai990004924,02ai990004955,02ai990004958,02ai990005031,02ai990005040,02ai990005047,02ai990005049,02ai990005074,02ai990005080,02ai990005088,02ai990005089,02ai990005154,02ai990005157,02ai990005158,02ai990005170,02ai990005186,02ai990005194,02ai990005203,02ai990005208,02ai990005211,02ai990005213,02ai990005225,02ai990005259,02ai990005261,02ai990005278,02ai990005304,02ai990005309,02ai990005315,02ai990005321,02ai990005345,02ai990005383,02ai990005389,02ai990005390,02ai990005394,02ai990005420,02ai990005439,02ai990005452,02ai990005456,02ai990005460,02ai990005463,02ai990005472,02ai990005508,02ai990005537,02ai990005566,02ai990005582,02ai990005598,02ai990005607,02ai990005612,02ai990005631,02ai990005662,02ai990005664,02ai990005686,02ai990005692,02ai990005712,02ai990005714,02ai990005716,02ai990005726,02ai990005737,02ai990005742,02ai990005749,02ai990005757,02ai990005774,02ai990005779,02ai990005789,02ai990005807,02ai990005823,02ai990005867,02ai990005894,02ai990005909,02ai990005914,02ai990005917,02ai990005927,02ai990005958,02ai990005994,02ai990005998,02ai990006015,02ai990006023,02ai990006035,02ai990006056,02ai990006064,02ai990006067,02ai990006115,02ai990006129,02ai990006155,02ai990006218,02ai990006229,02ai990006277,02ai990006282,02ai990006303,02ai990006331,02ai990006349,02ai990006385,02ai990006397,02ai990006420,02ai990006438,02ai990006445,02ai990006465,02ai990006499,02ai990006503,02ai990006508,02ai990006521,02ai990006531,02ai990006533,02ai990006548,02ai990006573,02ai990006606,02ai990006611,02ai990006620,02ai990006630,02ai990006635,02ai990006649,02ai990006672,02ai990006693,02ai990006739,02ai990006742,02ai990006745,02ai990006777,02ai990006788,02ai990006790,02ai990006794,02ai990006800,02ai990006807,02ai990006811,02ai990006863,02ai990006881,02ai990006897,02ai990006902,02ai990006912,02ai990006934,02ai990006948,02ai990006978,02ai990007004,02ai990007043,02ai990007065,02ai990007068,02ai990007076,02ai990007100,02ai990007126,02ai990007128,02ai990007131,02ai990007141,02ai990007149,02ai990007160,02ai990007176,02ai990007181,02ai990007232,02ai990007241,02ai990007249,02ai990007260,02ai990007287,02ai990007311,02ai990007318,02ai990007332,02ai990007352,02ai990007360,02ai990007381,02ai990007399,02ai990007408,02ai990007417,02ai990007436,02ai990007438,02ai990007447,02ai990007469,02ai990007495,02ai990007507,02ai990007509,02ai990007521,02ai990007526,02ai990007543,02ai990007553,02ai990007555,02ai990007560,02ai990007563,02ai990007576,02ai990007603,02ai990007605,02ai990007612,02ai990007634,02ai990007663,02ai990007667,02ai990007692,02ai990007707,02ai990007722,02ai990007729,02ai990007750,02ai990007751,02ai990007754,02ai990007784,02ai990007802,02ai990007809,02ai990007811,02ai990007829,02ai990007832,02ai990007866,02ai990007883,02ai990007914,02ai990007921,02ai990007946,02ai990007976,02ai990007977,02ai990007990,02ai990007991,02ai990007999,02ai990008003,02ai990008017,02ai990008032,02ai990008042,02ai990008046,02ai990008050,02ai990008064,02ai990008067,02ai990008068,02ai990008095,02ai990008114,02ai990008139,02ai990008140,02ai990008157,02ai990008176,02ai990008184,02ai990008190,02ai990008242,02ai990008244,02ai990008261,02ai990008264,02ai990008265,02ai990008273,02ai990008306,02ai990008334,02ai990008346,02ai990008372,02ai990008387,02ai990008390,02ai990008395,02ai990008410,02ai990008415,02ai990008418,02ai990008438,02ai990008442,02ai990008453,02ai990008471,02ai990008489,02ai990008513,02ai990008517,02ai990008520,02ai990008528,02ai990008529,02ai990008538,02ai990008547,02ai990008572,02ai990008600,02ai990008602,02ai990008612,02ai990008627,02ai990008640,02ai990008643,02ai990008675,02ai990008686,02ai990008701,02ai990008762,02ai990008763,02ai990008776,02ai990008790,02ai990008801,02ai990008833,02ai990008838,02ai990008840,02ai990008853,02ai990008865,02ai990008885,02ai990008888,02ai990008931,02ai990008932,02ai990008933,02ai990009007,02ai990009008,02ai990009017,02ai990009036,02ai990009039,02ai990009045,02ai990009082,02ai990009095,02ai990009105,02ai990009108,02ai990009111,02ai990009116,02ai990009120,02ai990009124,02ai990009136,02ai990009138,02ai990009140,02ai990009146,02ai990009150,02ai990009162,02ai990009172,02ai990009233,02ai990009240,02ai990009243,02ai990009245,02ai990009248,02ai990009262,02ai990009277,02ai990009281,02ai990009284,02ai990009290,02ai990009302,02ai990009307,02ai990009309,02ai990009354,02ai990009364,02ai990009382,02ai990009389,02ai990009395,02ai990009405,02ai990009480,02ai990009502,02ai990009507,02ai990009534,02ai990009589,02ai990009595,02ai990009615,02ai990009665,02ai990009679,02ai990009681,02ai990009706,02ai990009710,02ai990009736,02ai990009756,02ai990009780,02ai990009797,02ai990009799,02ai990009820,02ai990009826,02ai990009847,02ai990009870,02ai990009880,02ai990009894,02ai990009910,02ai990009932,02ai990009961,02ai990009982,02ai990009999,02ak990010007,02ak990010032,02ak990010055,02ak990010074,02ak990010112,02ak990010122,02ak990010136,02ak990010137,02ak990010140,02ak990010148,02ak990010151,02ak990010215,02ak990010220,02ak990010234,02ak990010241,02ak990010245,02ak990010251,02ak990010266,02ak990010285,02ak990010298,02ak990010300,02ak990010301,02ak990010302,02ak990010319,02ak990010336,02ak990010370,02ak990010385,02ak990010393,02ak990010396,02ak990010405,02ak990010412,02ak990010414,02ak990010426,02ak990010436,02ak990010463,02ak990010466,02ak990010475,02ak990010501,02ak990010508,02ak990010530,02ak990010551,02ak990010560,02ak990010561,02ak990010577,02ak990010584,02ak990010597,02ak990010604,02ak990010616,02ak990010628,02ak990010631,02ak990010660,02ak990010664,02ak990010671,02ak990010682,02ak990010722,02ak990010723,02ak990010730,02ak990010734,02ak990010741,02ak990010773,02ak990010777,02ak990010779,02ak990010780,02ak990010781,02ak990010783,02ak990010785,02ak990010792,02ak990010797,02ak990010798,02ak990010823,02ak990010833,02ak990010834,02ak990010842,02ak990010849,02ak990010850,02ak990010859,02ak990010862,02ak990010867,02ak990010878,02ak990010885,02ak990010889,02ak990010900,02ak990010905,02ak990010910,02ak990010912,02ak990010921,02ak990010933,02ak990010934,02ak990010936,02ak990010945,02ak990010986,02ak990010993,02ak990011015,02ak990011031,02ak990011044,02ak990011067,02ak990011068,02ak990011075,02ak990011090,02ak990011100,02ak990011117,02ak990011120,02ak990011124,02ak990011127,02ak990011145,02ak990011147,02ak990011155,02ak990011170,02ak990011187,02ak990011189,02ak990011211,02ak990011216,02ak990011232,02ak990011233,02ak990011275,02ak990011283,02ak990011284,02ak990011295,02ak990011299,02ak990011307,02ak990011343,02ak990011360,02ak990011381,02ak990011383,02ak990011385,02ak990011398,02ak990011408,02ak990011414,02ak990011424,02ak990011426,02ak990011436,02ak990011507,02ak990011513,02ak990011516,02ak990011517,02ak990011536,02ak990011543,02ak990011551,02ak990011559,02ak990011569,02ak990011576,02ak990011582,02ak990011602,02ak990011613,02ak990011620,02ak990011622,02ak990011641,02ak990011649,02ak990011660,02ak990011668,02ak990011680,02ak990011684,02ak990011693,02ak990011695,02ak990011696,02ak990011699,02ak990011711,02ak990011714,02ak990011716,02ak990011718,02ak990011735,02ak990011749,02ak990011755,02ak990011762,02ak990011778,02ak990011787,02ak990011791,02ak990011797,02ak990011818,02ak990011834,02ak990011864,02ak990011881,02ak990011897,02ak990011903,02ak990011912,02ak990011939,02ak990011974,02ak990011996,02ak990012008,02ak990012018,02ak990012025,02ak990012034,02ak990012060,02ak990012080,02ak990012102,02ak990012144,02ak990012146,02ak990012152,02ak990012157,02ak990012158,02ak990012185,02ak990012187,02ak990012191,02ak990012193,02ak990012195,02ak990012198,02ak990012205,02ak990012218,02ak990012226,02ak990012231,02ak990012232,02ak990012245,02ak990012246,02ak990012248,02ak990012249,02ak990012261,02ak990012275,02ak990012278,02ak990012287,02ak990012311,02ak990012322,02ak990012327,02ak990012341,02ak990012374,02ak990012390,02ak990012438,02ak990012440,02ak990012448,02ak990012453,02ak990012462,02ak990012471,02ak990012476,02ak990012484,02ak990012490,02ak990012496,02ak990012513,02ak990012527,02ak990012546,02ak990012553,02ak990012554,02ak990012562,02ak990012573,02ak990012581,02ak990012583,02ak990012585,02ak990012590,02ak990012598,02ak990012599,02ak990012602,02ak990012611,02ak990012616,02ak990012627,02ak990012641,02ak990012648,02ak990012655,02ak990012662,02ak990012667,02ak990012670,02ak990012695,02ak990012715,02ak990012728,02ak990012730,02ak990012741,02ak990012749,02ak990012753,02ak990012768,02ak990012771,02ak990012774,02ak990012796,02ak990012801,02ak990012802,02ak990012818,02ak990012839,02ak990012842,02ak990012855,02ak990012858,02ak990012861,02ak990012875,02ak990012877,02ak990012880,02ak990012891,02ak990012892,02ak990012906,02ak990012907,02ak990012918,02ak990012928,02ak990012932,02ak990012961,02ak990012964,02ak990012965,02ak990012972,02ak990012985,02ak990012986,02ak990012987,02ak990013021,02ak990013034,02ak990013037,02ak990013042,02ak990013048,02ak990013066,02ak990013067,02ak990013068,02ak990013070,02ak990013071,02ak990013099,02ak990013101,02ak990013110,02ak990013124,02ak990013136,02ak990013139,02ak990013165,02ak990013171,02ak990013172,02ak990013175,02ak990013183,02ak990013188,02ak990013211,02ak990013221,02ak990013237,02ak990013238,02ak990013246,02ak990013275,02ak990013279,02ak990013293,02ak990013295,02ak990013301,02ak990013303,02ak990013325,02ak990013337,02ak990013342,02ak990013343,02ak990013351,02ak990013356,02ak990013368,02ak990013369,02ak990013375,02ak990013382,02ak990013401,02ak990013402,02ak990013407,02ak990013414,02ak990013426,02ak990013427,02ak990013444,02ak990013464,02ak990013466,02ak990013481,02ak990013485,02ak990013518,02ak990013520,02ak990013531,02ak990013545,02ak990013561,02ak990013571,02ak990013632,02ak990013635,02ak990013637,02ak990013645,02ak990013660,02ak990013663,02ak990013664,02ak990013668,02ak990013675,02ak990013691,02ak990013706,02ak990013717,02ak990013729,02ak990013733,02ak990013745,02ak990013748,02ak990013765,02ak990013768,02ak990013776,02ak990013780,02ak990013789,02ak990013794,02ak990013810,02ak990013817,02ak990013828,02ak990013840,02ak990013870,02ak990013875,02ak990013877,02ak990013882,02ak990013884,02ak990013888,02ak990013891,02ak990013892,02ak990013907,02ak990013911,02ak990013925,02ak990013936,02ak990013942,02ak990013946,02ak990013955,02ak990013958,02ak990013962,02ak990013967,02ak990013970,02ak990013973,02ak990013975,02ak990013995,02ak990014011,02ak990014015,02ak990014029,02ak990014035,02ak990014038,02ak990014050,02ak990014052,02ak990014053,02ak990014067,02ak990014069,02ak990014081,02ak990014082,02ak990014133,02ak990014161,02ak990014165,02ak990014170,02ak990014181,02ak990014192,02ak990014209,02ak990014232,02ak990014286,02ak990014292,02ak990014308,02ak990014315,02ak990014317,02ak990014347,02ak990014350,02ak990014358,02ak990014367,02ak990014373,02ak990014377,02ak990014397,02ak990014399,02ak990014404,02ak990014408,02ak990014420,02ak990014424,02ak990014432,02ak990014438,02ak990014442,02ak990014443,02ak990014446,02ak990014450,02ak990014451,02ak990014454,02ak990014463,02ak990014484,02ak990014486,02ak990014497,02ak990014498,02ak990014510,02ak990014526,02ak990014531,02ak990014540,02ak990014546,02ak990014557,02ak990014559,02ak990014583,02ak990014591,02ak990014596,02ak990014597,02ak990014612,02ak990014634,02ak990014641,02ak990014665,02ak990014675,02ak990014686,02ak990014706,02ak990014711,02ak990014716,02ak990014740,02ak990014750,02ak990014753,02ak990014761,02ak990014787,02ak990014789,02ak990014792,02ak990014794,02ak990014803,02ak990014808,02ak990014817,02ak990014830,02ak990014831,02ak990014837,02ak990014840,02ak990014842,02ak990014857,02ak990014873,02ak990014883,02ak990014913,02ak990014921,02ak990014932,02ak990014948,02ak990014956,02ak990014957,02ak990014962,02ak990014976,02ak990014978,02ak990014985,02ak990014987,02ak990014995,02ak990014998,02ak990015001,02ak990015008,02ak990015017,02ak990015021,02ak990015026,02ak990015050,02ak990015061,02ak990015069,02ak990015071,02ak990015076,02ak990015077,02ak990015088,02ak990015111,02ak990015119,02ak990015125,02ak990015150,02ak990015153,02ak990015155,02ak990015161,02ak990015189,02ak990015190,02ak990015203,02ak990015230,02ak990015239,02ak990015242,02ak990015256,02ak990015261,02ak990015287,02ak990015293,02ak990015294,02ak990015296,02ak990015299,02ak990015317,02ak990015324,02ak990015338,02ak990015343,02ak990015346,02ak990015349,02ak990015353,02ak990015373,02ak990015384,02ak990015386,02ak990015400,02ak990015405,02ak990015417,02ak990015440,02ak990015442,02ak990015446,02ak990015460,02ak990015466,02ak990015473,02ak990015476,02ak990015496,02ak990015500,02ak990015510,02ak990015516,02ak990015522,02ak990015526,02ak990015529,02ak990015542,02ak990015549,02ak990015563,02ak990015573,02ak990015575,02ak990015580,02ak990015588,02ak990015590,02ak990015602,02ak990015620,02ak990015623,02ak990015632,02ak990015650,02ak990015656,02ak990015661,02ak990015672,02ak990015673,02ak990015683,02ak990015685,02ak990015691,02ak990015696,02ak990015705,02ak990015719,02ak990015731,02ak990015736,02ak990015750,02ak990015758,02ak990015766,02ak990015769,02ak990015773,02ak990015777,02ak990015794,02ak990015796,02ak990015806,02ak990015811,02ak990015812,02ak990015832,02ak990015852,02ak990015861,02ak990015866,02ak990015881,02ak990015888,02ak990015889,02ak990015891,02ak990015899,02ak990015908,02ak990015910,02ak990015911,02ak990015922,02ak990015935,02ak990015947,02ak990015954,02ak990015983,02ak990015989,02ak990016029,02ak990016058,02ak990016086,02ak990016102,02ak990016138,02ak990016152,02ak990016156,02ak990016158,02ak990016162,02ak990016173,02ak990016178,02ak990016195,02ak990016217,02ak990016219,02ak990016220,02ak990016221,02ak990016223,02ak990016232,02ak990016255,02ak990016270,02ak990016276,02ak990016283,02ak990016311,02ak990016323,02ak990016339,02ak990016385,02ak990016402,02ak990016410,02ak990016426,02ak990016439,02ak990016441,02ak990016450,02ak990016452,02ak990016456,02ak990016467,02ak990016472,02ak990016478,02ak990016497,02ak990016503,02ak990016531,02ak990016534,02ak990016543,02ak990016574,02ak990016575,02ak990016596,02ak990016603,02ak990016610,02ak990016677,02ak990016680,02ak990016698,02ak990016703,02ak990016762,02ak990016776,02ak990016784,02ak990016810,02ak990016819,02ak990016825,02ak990016831,02ak990016840,02ak990016845,02ak990016848,02ak990016855,02ak990016863,02ak990016872,02ak990016890,02ak990016894,02ak990016898,02ak990016899,02ak990016901,02ak990016916,02ak990016917,02ak990016922,02ak990016925,02ak990016942,02ak990016979,02ak990016989,02ak990016996,02ak990016998,02ak990017011,02ak990017012,02ak990017020,02ak990017032,02ak990017033,02ak990017042,02ak990017043,02ak990017046,02ak990017076,02ak990017082,02ak990017088,02ak990017095,02ak990017100,02ak990017110,02ak990017117,02ak990017130,02ak990017142,02ak990017143,02ak990017144,02ak990017146,02ak990017152,02ak990017163,02ak990017178,02ak990017183,02ak990017188,02ak990017191,02ak990017200,02ak990017206,02ak990017207,02ak990017219,02ak990017227,02ak990017239,02ak990017253,02ak990017259,02ak990017276,02ak990017293,02ak990017309,02ak990017315,02ak990017320,02ak990017326,02ak990017331,02ak990017342,02ak990017346,02ak990017365,02ak990017368,02ak990017375,02ak990017383,02ak990017392,02ak990017394,02ak990017398,02ak990017401,02ak990017402,02ak990017410,02ak990017418,02ak990017430,02ak990017441,02ak990017468,02ak990017470,02ak990017486,02ak990017491,02ak990017492,02ak990017500,02ak990017519,02ak990017524,02ak990017546,02ak990017552,02ak990017553,02ak990017561,02ak990017562,02ak990017592,02ak990017598,02ak990017625,02ak990017636,02ak990017637,02ak990017638,02ak990017644,02ak990017661,02ak990017664,02ak990017665,02ak990017674,02ak990017692,02ak990017701,02ak990017703,02ak990017709,02ak990017721,02ak990017725,02ak990017729,02ak990017745,02ak990017746,02ak990017751,02ak990017766,02ak990017768,02ak990017780,02ak990017783,02ak990017788,02ak990017798,02ak990017800,02ak990017806,02ak990017808,02ak990017814,02ak990017852,02ak990017858,02ak990017860,02ak990017880,02ak990017883,02ak990017891,02ak990017894,02ak990017896,02ak990017905,02ak990017924,02ak990017932,02ak990017944,02ak990017949,02ak990017950,02ak990017954,02ak990017956,02ak990017960,02ak990017973,02ak990017974,02ak990018005,02ak990018024,02ak990018028,02ak990018029,02ak990018033,02ak990018040,02ak990018048,02ak990018053,02ak990018055,02ak990018056,02ak990018065,02ak990018069,02ak990018091,02ak990018098,02ak990018101,02ak990018107,02ak990018110,02ak990018125,02ak990018138,02ak990018143,02ak990018144,02ak990018150,02ak990018155,02ak990018157,02ak990018187,02ak990018195,02ak990018213,02ak990018219,02ak990018220,02ak990018230,02ak990018231,02ak990018233,02ak990018242,02ak990018244,02ak990018245,02ak990018266,02ak990018268,02ak990018289,02ak990018308,02ak990018312,02ak990018315,02ak990018334,02ak990018340,02ak990018347,02ak990018348,02ak990018349,02ak990018354,02ak990018360,02ak990018367,02ak990018373,02ak990018383,02ak990018384,02ak990018396,02ak990018402,02ak990018403,02ak990018406,02ak990018440,02ak990018468,02ak990018475,02ak990018476,02ak990018482,02ak990018483,02ak990018491,02ak990018496,02ak990018515,02ak990018520,02ak990018536,02ak990018549,02ak990018558,02ak990018569,02ak990018570,02ak990018573,02ak990018574,02ak990018584,02ak990018607,02ak990018609,02ak990018621,02ak990018641,02ak990018644,02ak990018645,02ak990018650,02ak990018651,02ak990018668,02ak990018680,02ak990018686,02ak990018691,02ak990018708,02ak990018712,02ak990018713,02ak990018714,02ak990018726,02ak990018732,02ak990018742,02ak990018771,02ak990018779,02ak990018784,02ak990018787,02ak990018804,02ak990018808,02ak990018813,02ak990018826,02ak990018832,02ak990018834,02ak990018847,02ak990018861,02ak990018862,02ak990018866,02ak990018882,02ak990018897,02ak990018899,02ak990018933,02ak990018937,02ak990018946,02ak990018966,02ak990018973,02ak990018975,02ak990018976,02ak990018979,02ak990018989,02ak990018998,02ak990019004,02ak990019041,02ak990019052,02ak990019075,02ak990019080,02ak990019081,02ak990019089,02ak990019090,02ak990019099,02ak990019114,02ak990019117,02ak990019132,02ak990019138,02ak990019148,02ak990019156,02ak990019160,02ak990019164,02ak990019174,02ak990019178,02ak990019180,02ak990019194,02ak990019205,02ak990019207,02ak990019213,02ak990019214,02ak990019216,02ak990019219,02ak990019222,02ak990019229,02ak990019236,02ak990019242,02ak990019248,02ak990019255,02ak990019263,02ak990019273,02ak990019280,02ak990019283,02ak990019285,02ak990019299,02ak990019318,02ak990019326,02ak990019349,02ak990019356,02ak990019357,02ak990019393,02ak990019418,02ak990019440,02ak990019457,02ak990019458,02ak990019462,02ak990019473,02ak990019491,02ak990019493,02ak990019495,02ak990019499,02ak990019505,02ak990019508,02ak990019516,02ak990019520,02ak990019521,02ak990019534,02ak990019535,02ak990019539,02ak990019553,02ak990019555,02ak990019559,02ak990019569,02ak990019572,02ak990019585,02ak990019593,02ak990019604,02ak990019605,02ak990019610,02ak990019640,02ak990019646,02ak990019675,02ak990019678,02ak990019700,02ak990019719,02ak990019742,02ak990019745,02ak990019761,02ak990019769,02ak990019770,02ak990019777,02ak990019798,02ak990019812,02ak990019823,02ak990019824,02ak990019827,02ak990019840,02ak990019841,02ak990019842,02ak990019851,02ak990019852,02ak990019853,02ak990019854,02ak990019868,02ak990019873,02ak990019885,02ak990019912,02ak990019920,02ak990019926,02ak990019934,02ak990019935,02ak990019954,02ak990019960,02ak990019986,02ak990019995,02ak990019998,02ak990020000,02ak990020050,02ak990020052,02ak990020062,02ak990020065,02ak990020070,02ak990020074,02ak990020080,02ak990020097,02ak990020102,02ak990020111,02ak990020122,02ak990020124,02ak990020127,02ak990020131,02ak990020147,02ak990020148,02ak990020190,02ak990020195,02ak990020201,02ak990020203,02ak990020214,02ak990020231,02ak990020251,02ak990020268,02ak990020299,02ak990020303,02ak990020309,02ak990020310,02ak990020319,02ak990020326,02ak990020340,02ak990020349,02ak990020363,02ak990020376,02ak990020382,02ak990020401,02ak990020407,02ak990020437,02ak990020439,02ak990020440,02ak990020456,02ak990020458,02ak990020463,02ak990020465,02ak990020469,02ak990020471,02ak990020478,02ak990020481,02ak990020496,02ak990020499,02ak990020508,02ak990020515,02ak990020517,02ak990020534,02ak990020543,02ak990020544,02ak990020545,02ak990020554,02ak990020564,02ak990020590,02ak990020595,02ak990020596,02ak990020603,02ak990020606,02ak990020619,02ak990020623,02ak990020650,02ak990020659,02ak990020662,02ak990020663,02ak990020665,02ak990020669,02ak990020675,02ak990020678,02ak990020684,02ak990020688,02ak990020693,02ak990020697,02ak990020707,02ak990020730,02ak990020746,02ak990020751,02ak990020753,02ak990020768,02ak990020784,02ak990020790,02ak990020793,02ak990020795,02ak990020801,02ak990020810,02ak990020814,02ak990020816,02ak990020817,02ak990020818,02ak990020824,02ak990020834,02ak990020852,02ak990020859,02ak990020860,02ak990020863,02ak990020868,02ak990020869,02ak990020894,02ak990020901,02ak990020904,02ak990020915,02ak990020923,02ak990020924,02ak990020960,02ak990020965,02ak990020967,02ak990020980,02ak990020982,02ak990020994,02ak990021011,02ak990021022,02ak990021035,02ak990021039,02ak990021044,02ak990021047,02ak990021055,02ak990021068,02ak990021071,02ak990021074,02ak990021084,02ak990021094,02ak990021107,02ak990021144,02ak990021146,02ak990021169,02ak990021173,02ak990021189,02ak990021220,02ak990021222,02ak990021226,02ak990021233,02ak990021238,02ak990021267,02ak990021274,02ak990021288,02ak990021298,02ak990021309,02ak990021311,02ak990021314,02ak990021327,02ak990021328,02ak990021333,02ak990021340,02ak990021342,02ak990021380,02ak990021392,02ak990021398,02ak990021399,02ak990021408,02ak990021426,02ak990021480,02ak990021483,02ak990021484,02ak990021491,02ak990021495,02ak990021496,02ak990021508,02ak990021509,02ak990021511,02ak990021513,02ak990021516,02ak990021523,02ak990021554,02ak990021557,02ak990021563,02ak990021566,02ak990021567,02ak990021573,02ak990021587,02ak990021589,02ak990021595,02ak990021624,02ak990021649,02ak990021654,02ak990021700,02ak990021719,02ak990021726,02ak990021738,02ak990021744,02ak990021768,02ak990021801,02ak990021823,02ak990021842,02ak990021843,02ak990021844,02ak990021845,02ak990021849,02ak990021855,02ak990021880,02ak990021885,02ak990021897,02ak990021909,02ak990021920,02ak990021946,02ak990021952,02ak990021962,02ak990021981,02ak990022007,02ak990022012,02ak990022013,02ak990022018,02ak990022019,02ak990022023,02ak990022031,02ak990022071,02ak990022075,02ak990022079,02ak990022085,02ak990022094,02al990022105,02al990022111,02al990022138,02al990022142,02al990022148,02al990022150,02al990022154,02al990022166,02al990022169,02al990022172,02al990022177,02al990022182,02al990022191,02al990022216,02al990022218,02al990022224,02al990022227,02al990022254,02al990022257,02al990022258,02al990022260,02al990022261,02al990022263,02al990022266,02al990022269,02al990022270,02al990022272,02al990022273,02al990022274,02al990022275,02al990022296,02al990022303,02al990022309,02al990022317,02al990022320,02al990022338,02al990022339,02al990022341,02al990022346,02al990022355,02al990022360,02al990022361,02al990022371,02al990022384,02al990022394,02al990022397,02al990022410,02al990022419,02al990022424,02al990022426,02al990022430,02al990022431,02al990022432,02al990022437,02al990022444,02al990022446,02al990022454,02al990022470,02al990022484,02al990022490,02al990022496,02al990022500,02al990022508,02al990022509,02al990022520,02al990022524,02al990022531,02al990022533,02al990022547,02al990022552,02al990022553,02al990022560,02al990022584,02al990022585,02al990022600,02al990022608,02al990022621,02al990022625,02al990022627,02al990022632,02al990022640,02al990022655,02al990022657,02al990022668,02al990022676,02al990022677,02al990022688,02al990022698,02al990022706,02al990022707,02al990022709,02al990022718,02al990022724,02al990022734,02al990022737,02al990022748,02al990022750,02al990022751,02al990022753,02al990022760,02al990022762,02al990022775,02al990022785,02al990022791,02al990022792,02al990022793,02al990022796,02al990022798,02al990022808,02al990022809,02al990022825,02al990022830,02al990022848,02al990022854,02al990022864,02al990022877,02al990022887,02al990022902,02al990022906,02al990022915,02al990022917,02al990022924,02al990022927,02al990022931,02al990022932,02al990022933,02al990022941,02al990022956,02al990022957,02al990022971,02al990022973,02al990022982,02al990022984,02al990022989,02al990022997,02al990023013,02ai990008569";
        String[] sArray = str.split(",");
        for(int i=0;i<sArray.length;i++) {
            int index = i+1;
            System.out.println("=====================处理第 "+ index+" 个设备");
            String dtu = sArray[i];
            GetDeviceObdTcpLogInfoDO getDeviceObdTcpLogInfoDO = new GetDeviceObdTcpLogInfoDO();
            getDeviceObdTcpLogInfoDO.setDtu(dtu);
            getDeviceObdTcpLogInfoDO.setSortRow("createTime");
            getDeviceObdTcpLogInfoDO.setSortOrder("desc");
            getDeviceObdTcpLogInfoDO.setPage(1);
            getDeviceObdTcpLogInfoDO.setPageSize(1);
            List<DeviceObdTcpLogInfo> logList = deviceObdTcpLogInfoService.getPageList(getDeviceObdTcpLogInfoDO);
            String message = dtu+" - ";
            Date date = null ;
            if(logList!=null && logList.size()>0){
                date = logList.get(0).getCreateTime();
            }
            if(date == null){
                message+= "data无数据";
            }else{
                try {
                    String tableName = "device_obd_gps_info_";
                    String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                    dayStr = dayStr.replaceAll("-", "");
                    message += DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + " - ";
                    GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                    getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
                    getDeviceObdGpsInfoDO.setSortRow("createTime");
                    getDeviceObdGpsInfoDO.setSortOrder("desc");
                    getDeviceObdGpsInfoDO.setDtu(dtu);
                    List<DeviceObdGpsInfo> list = deviceObdGpsInfoService.getAllList(getDeviceObdGpsInfoDO);
                    if (list != null && list.size() > 0) {
                        boolean flag = checkObdGps(list);
                        if(flag)message+="定位正常"+" - "+list.size();
                        else message+="定位异常"+" - "+list.size();
                    } else {
                        message += "无定位 - 0";
                    }
                }catch (Exception e){
                    message+="出错了 - 0";
                }
                String file = "d:/test/gps.txt";
                try {
                    // 创建FileWriter对象
                    FileWriter fileWriter = new FileWriter(file, true);

                    // 创建BufferedWriter对象
                    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

                    // 写入内容
                    bufferedWriter.write(message);
                    bufferedWriter.newLine();

                    // 关闭BufferedWriter和FileWriter
                    bufferedWriter.close();
                    fileWriter.close();

                    System.out.println("写入成功！");
                } catch (IOException e) {
                    System.out.println("写入失败：" + e.getMessage());
                }
            }
        }*/
        /*GetDeviceObdBaseInfoDO getDeviceObdBaseInfoDO = new GetDeviceObdBaseInfoDO();
        getDeviceObdBaseInfoDO.setSortRow("id");
        getDeviceObdBaseInfoDO.setSortOrder("asc");
        List<DeviceObdBaseInfo> baseList = deviceObdBaseInfoService.getAllList(getDeviceObdBaseInfoDO);
        int index = 0;
        for(DeviceObdBaseInfo baseInfo:baseList){
//            if(index == 10)break;
            if(baseInfo.getFactoryUserId()!=null && baseInfo.getFactoryUserId()>0){
                GetDeviceObdTcpLogInfoDO getDeviceObdTcpLogInfoDO = new GetDeviceObdTcpLogInfoDO();
                getDeviceObdTcpLogInfoDO.setDtu(baseInfo.getDtu());
                getDeviceObdTcpLogInfoDO.setPage(1);
                getDeviceObdTcpLogInfoDO.setPageSize(1);
                getDeviceObdTcpLogInfoDO.setSortRow("createTime");
                getDeviceObdTcpLogInfoDO.setSortOrder("desc");
                List<DeviceObdTcpLogInfo> tcpList = deviceObdTcpLogInfoService.getPageList(getDeviceObdTcpLogInfoDO);
                if(tcpList!=null && tcpList.size()>0){
                    DataObdTcpLogInfo info = EntityConversionUtil.copy(tcpList.get(0), DataObdTcpLogInfo.class);
                    dataObdTcpLogInfoService.save(info);
                    index++;
                    System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&设备号： "+ info.getDtu());
                }
            }
        }*/
        /*GetDataObdTcpLogInfoDO getDataObdTcpLogInfoDO = new GetDataObdTcpLogInfoDO();
        getDataObdTcpLogInfoDO.setContent("%|1.7.7|0|&&");
        getDataObdTcpLogInfoDO.setSortRow("createTime");
        getDataObdTcpLogInfoDO.setSortOrder("asc");
        getDataObdTcpLogInfoDO.setStatus(0);
        List<DataObdTcpLogInfo> tcpList = dataObdTcpLogInfoService.getAll(getDataObdTcpLogInfoDO);
        for(int i =0;i<tcpList.size();i++){
            System.out.println("/////////////////////i :" + i);
            DataObdTcpLogInfo tcpInfo = tcpList.get(i);
            //获取定位信息
            String tableName = "device_obd_gps_info_";
            Date date = tcpInfo.getCreateTime();
            int year = Integer.parseInt(DateUtils.getYear(date));
            int month = Integer.parseInt(DateUtils.getMonth(date));
            int day = Integer.parseInt(DateUtils.getDate(date));
            if(year==2022 || ( year == 2023 && month <9)) {
                String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                dayStr = dayStr.replaceAll("-", "");
                GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
                getDeviceObdGpsInfoDO.setSortRow("createTime");
                getDeviceObdGpsInfoDO.setSortOrder("desc");
                getDeviceObdGpsInfoDO.setPageSize(2);
                getDeviceObdGpsInfoDO.setDtu(tcpInfo.getDtu());
                List<DeviceObdGpsInfo> list = deviceObdGpsInfoService.getPageList(getDeviceObdGpsInfoDO);
                if (list != null && list.size() > 0) {
                    DeviceObdGpsInfo info = list.get(0);
                    tcpInfo.setGpsTime(info.getCreateTime());
                    dataObdTcpLogInfoService.update(tcpInfo);
                }
            }*/
        //获取工况
            /*String tableName = "device_25_obd_info_";
            Date date = tcpInfo.getCreateTime();
            int year = Integer.parseInt(DateUtils.getYear(date));
            int month = Integer.parseInt(DateUtils.getMonth(date));
            int day = Integer.parseInt(DateUtils.getDate(date));
            if(year!=2023 ||(year == 2023 && month!=8&&month!=7)||(year==2023&&month==6&&day<8))continue;
            String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
            dayStr = dayStr.replaceAll("-", "");
            GetDevice25ObdInfoDO getDevice25ObdInfoDO = new GetDevice25ObdInfoDO();
            getDevice25ObdInfoDO.setTableName(tableName + dayStr);
            getDevice25ObdInfoDO.setDtu(tcpInfo.getDtu());
            getDevice25ObdInfoDO.setSortRow("createTime");
            getDevice25ObdInfoDO.setSortOrder("desc");
            getDevice25ObdInfoDO.setPage(1);
            getDevice25ObdInfoDO.setPageSize(2);
            List<Device25ObdInfo> gkList = device25ObdInfoService.getPageList(getDevice25ObdInfoDO);
            if(gkList!=null && gkList.size()>0){
                Device25ObdInfo gkInfo = gkList.get(0);
                tcpInfo.setGzm(gkInfo.getGzm());
                tcpInfo.setGkTime(gkInfo.getCreateTime());
                dataObdTcpLogInfoService.update(tcpInfo);
            }
        }*/

        Date date = DateUtils.parseStrToDate("2023-11-01", DateUtils.DATE_FORMAT_YYYY_MM_DD);
        try {
            Date lastDate = DateUtils.parseStrToDate("2023-08-01", DateUtils.DATE_FORMAT_YYYY_MM_DD);
            boolean flag = true;
            while (flag) {
                String tableName = "device_obd_gps_info_";
                date = DateUtils.addDays(date, -1);
                System.out.println("=========================date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                log.info("========================= 数据date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                dayStr = dayStr.replaceAll("-", "");
                GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
                List<Map<String, Object>> list = deviceObdGpsInfoService.getListGroupBy(getDeviceObdGpsInfoDO);
                if (list != null && list.size() > 0) {
                    for (Map<String, Object> item : list) {
                        String dtu = (String) item.get("dtu");
                        if (dtu.length() == 13) {
                            DeviceObdBaseInfo baseInfo = deviceObdBaseInfoService.getByDtu(dtu);
                            if (baseInfo != null && baseInfo.getBatchId() != null && baseInfo.getBatchId() < 16) {
                                String message = dtu + " - ";
                                try {
                                    getDeviceObdGpsInfoDO.setSortRow("createTime");
                                    getDeviceObdGpsInfoDO.setSortOrder("desc");
                                    getDeviceObdGpsInfoDO.setDtu(dtu);
                                    List<DeviceObdGpsInfo> gpsList = deviceObdGpsInfoService.getAllList(getDeviceObdGpsInfoDO);
                                    if (gpsList != null && gpsList.size() > 0) {
                                        boolean f = checkObdGps(gpsList);
                                        if (!f && gpsList.size() > 60) {
                                            message += DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + " - " + gpsList.size();
                                            FileUtils.writeFile(message, "d:/test/gps.txt");
                                        }
                                    }
                                } catch (Exception e) {
                                    message += DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + " - " + e.getMessage();
                                    FileUtils.writeFile(message, "d:/test/gps_error.txt");
                                }
                            }
                        }
                    }
                }
                if (DateUtils.compareIsSameDay(date, lastDate)) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("统计错误日志： " + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
        }
        return Result.suc();
    }

    @Log(title = "设备管理-统计OBDGPS和工况信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "统计OBDGPS和工况信息")
    @GetMapping("/testStatisticsObdGPSInfo")
    public Result<Objects> testStatisticsObdGPSInfo(@RequestParam String s) {
        //统计每天的GPS信息和工况信息数据
        Date date = DateUtils.addDate(DateUtils.parseStrToDate(s, DateUtils.DATE_FORMAT_YYYY_MM_DD), 0, 0, 1, 0, 0, 0, 0);
        try {
            Date lastDate = DateUtils.parseStrToDate(s, DateUtils.DATE_FORMAT_YYYY_MM_DD);
            boolean flag = true;
            while (flag) {
                String tableName = "device_obd_gps_info_";
                date = DateUtils.addDays(date, -1);
                System.out.println("=========================date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                log.info("========================= 数据date :" + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
                String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
                dayStr = dayStr.replaceAll("-", "");
                GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
                getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
                List<Map<String, Object>> list = deviceObdGpsInfoService.getListGroupBy(getDeviceObdGpsInfoDO);
                if (list != null && list.size() > 0) {
                    for (Map<String, Object> item : list) {
                        String dtu = (String) item.get("dtu");
                        if (dtu.length() == 13) {
                            DeviceObdBaseInfo baseInfo = deviceObdBaseInfoService.getByDtu(dtu);
                            if (baseInfo != null && baseInfo.getBatchId() != null && baseInfo.getBatchId() < 16) {
                                String message = dtu + " - ";
                                try {
                                    getDeviceObdGpsInfoDO.setDtu(dtu);
                                    int gpsCount = deviceObdGpsInfoService.countByDtu(getDeviceObdGpsInfoDO);
                                    GetDevice25ObdInfoDO getDevice25ObdInfoDO = new GetDevice25ObdInfoDO();
                                    getDevice25ObdInfoDO.setDtu(dtu);
                                    getDevice25ObdInfoDO.setTableName("device_25_obd_info_" + dayStr);
                                    int gkCount = device25ObdInfoService.countDtu(getDevice25ObdInfoDO);
                                    message += gpsCount + " - " + gkCount;
                                    FileUtils.writeFile(message, "d:/test/gps_gk_count.txt");
                                } catch (Exception e) {
                                    message += DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD) + " - " + e.getMessage();
                                    FileUtils.writeFile(message, "d:/test/gps_gk_count_error.txt");
                                }
                            }
                        }
                    }
                }
                if (DateUtils.compareIsSameDay(date, lastDate)) {
                    flag = false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("统计错误日志： " + DateUtils.parseDateToStr(date, DateUtils.DATE_FORMAT_YYYY_MM_DD));
        }
        return Result.suc();
    }


    private boolean checkObdGps(List<DeviceObdGpsInfo> gpsList) {
        boolean flag = false;
        for (DeviceObdGpsInfo info : gpsList) {
            if ("A".equals(info.getGpsType())) return true;
        }
        return flag;
    }


    @Log(title = "OBD终端管理-测试获取指定设备最后一条工况", businessType = BusinessType.SELECT)
    @ApiOperation(value = "测试获取指定设备最后一条工况")
    @GetMapping("/getLastGkInfo")
    public Result<Objects> getLastGkInfo() {
        GetDataObdTcpLogInfoDO getDataObdTcpLogInfoDO = new GetDataObdTcpLogInfoDO();
        List<DataObdTcpLogInfo> list = dataObdTcpLogInfoService.selectErrorList(getDataObdTcpLogInfoDO);
        int index = 0;
        for (DataObdTcpLogInfo info : list) {
            index++;
            DeviceObdBaseInfo baseInfo = deviceObdBaseInfoService.getByDtu(info.getDtu());
            System.out.println("=========获取工况，第" + index + "个设备");
            /*String tableName = "device_25_obd_info_";
            Date date = info.getGkTime();
            int year = Integer.parseInt(DateUtils.getYear(date));
            int month = Integer.parseInt(DateUtils.getMonth(date));
            int day = Integer.parseInt(DateUtils.getDate(date));
            String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
            dayStr = dayStr.replaceAll("-", "");
            GetDevice25ObdInfoDO getDevice25ObdInfoDO = new GetDevice25ObdInfoDO();
            getDevice25ObdInfoDO.setTableName(tableName + dayStr);
            getDevice25ObdInfoDO.setDtu(info.getDtu());
            getDevice25ObdInfoDO.setSortRow("createTime");
            getDevice25ObdInfoDO.setSortOrder("desc");
            getDevice25ObdInfoDO.setPage(1);
            getDevice25ObdInfoDO.setPageSize(2);
            List<Device25ObdInfo> gkList = device25ObdInfoService.getPageList(getDevice25ObdInfoDO);
            if(gkList!=null && gkList.size()>0){
                info.setZcgzsj(gkList.get(0).getZcgzsj());
                dataObdTcpLogInfoService.update(info);
            }*/

            String tableName = "device_obd_gps_info_";
            Date date = baseInfo.getDataTime();
            String dayStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
            dayStr = dayStr.replaceAll("-", "");
            GetDeviceObdGpsInfoDO getDeviceObdGpsInfoDO = new GetDeviceObdGpsInfoDO();
            getDeviceObdGpsInfoDO.setTableName(tableName + dayStr);
            getDeviceObdGpsInfoDO.setSortRow("createTime");
            getDeviceObdGpsInfoDO.setSortOrder("desc");
            getDeviceObdGpsInfoDO.setIsEffective("1");
            getDeviceObdGpsInfoDO.setPageSize(2);
            getDeviceObdGpsInfoDO.setDtu(info.getDtu());
            List<DeviceObdGpsInfo> gpsList = deviceObdGpsInfoService.getPageList(getDeviceObdGpsInfoDO);
            if (list != null && list.size() > 0) {
                DeviceObdGpsInfo gpsInfo = gpsList.get(0);
                info.setGpsContent(gpsInfo.getContent());
                info.setImei(baseInfo.getImei());
                dataObdTcpLogInfoService.update(info);
            }
        }
        return Result.suc();
    }

    @Log(title = "OBD终端管理-测试发送数据给环保部", businessType = BusinessType.SELECT)
    @ApiOperation(value = "测试发送数据给环保部")
    @GetMapping("/sendMessageToFJK")
    public Result<Objects> sendMessageToFJK(@RequestParam int type) {
        if (type == 1) {
            SocketTest.loginIn();
        } else if (type == 2) {
            SocketTest.sendGps("113.40354333333333", "22.8944285");
        } else if (type == 3) {
            SocketTest.loginOut();
        } else if (type == 4) {
            SocketTest.sendTamperAlarm("113.40354333333333", "22.8944285");
        } else if (type == 5) {
            SocketTest.loginInOfMachine();
        } else if (type == 6) {
            SocketTest.loginOutOfMachine();
        }
        return Result.suc();
    }

    @Log(title = "设备管理-定位异常设备列表", businessType = BusinessType.INSERT)
    @ApiOperation(value = "定位异常设备列表")
    @PostMapping("/getDeviceListByGpsError")
    public Result<PageResult<List<GetDeviceListByGpsErrorVO>>> getDeviceListByGpsError(@RequestBody @Valid GetDeviceListByGpsErrorDTO dto) {
        List<GetDeviceListByGpsErrorVO> voList = new ArrayList<>();
        GetDeviceGpsErrorStatisticsInfoDO getDeviceGpsErrorStatisticsInfoDO = EntityConversionUtil.copy(dto, GetDeviceGpsErrorStatisticsInfoDO.class);
        if (dto.getType() == 0) {
            getDeviceGpsErrorStatisticsInfoDO.setType(null);
        }
        getDeviceGpsErrorStatisticsInfoDO.setSortRow("ncount");
        List<DeviceGpsErrorStatisticsInfo> list = deviceGpsErrorStatisticsInfoService.getPageList(getDeviceGpsErrorStatisticsInfoDO);
        if (list != null && list.size() > 0) {
            list.forEach(item -> {
                GetDeviceListByGpsErrorVO vo = EntityConversionUtil.copy(item, GetDeviceListByGpsErrorVO.class);
                vo.setDate(item.getWorkDate());
                vo.setCount(item.getNcount());
                voList.add(vo);
            });
        }
        PageInfo<DeviceGpsErrorStatisticsInfo> pageInfo = new PageInfo<>(list);
        PageResult<List<GetDeviceListByGpsErrorVO>> build = PageResult.<List<GetDeviceListByGpsErrorVO>>builder().result(voList).pageInfo(pageInfo).build();
        return Result.suc(build);
    }

    @Log(title = "设备管理-APP终端列表", businessType = BusinessType.INSERT)
    @ApiOperation(value = "APP终端列表")
    @PostMapping("/getDeviceListInApp")
    public Result<PageResult<List<GetDeviceListInAppVO>>> getDeviceListInApp(@RequestBody @Valid GetDeviceListInAppDTO dto) {
        SysUser sysUser = sysUserService.getByUserId(dto.getUserId());
        List<GetDeviceListInAppVO> voList = new ArrayList<>();
        if (sysUser != null) {
            int userType = sysUser.getUserType();
            if(userType == Constants.SysUserUserType.TYPE_TBOX生产厂家||userType == Constants.SysUserUserType.TYPE_TBOX生产厂家2){
                GetDeviceObdBaseInfoDO getDeviceObdBaseInfoDO = EntityConversionUtil.copy(dto,GetDeviceObdBaseInfoDO.class);
                if(!"testadmin".equals(sysUser.getName()))getDeviceObdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                getDeviceObdBaseInfoDO.setSortRow("createTime");
                List<DeviceObdBaseInfo> baseList = deviceObdBaseInfoService.getPageList(getDeviceObdBaseInfoDO);
                if (baseList != null && baseList.size() > 0) {
                    baseList.forEach(item -> {
                        GetDeviceListInAppVO vo = EntityConversionUtil.copy(item, GetDeviceListInAppVO.class);
                        vo.setDeviceType(Constants.DeviceType.TYPE_TBOX);
                        vo.setDeviceId(item.getId());
                        voList.add(vo);
                    });
                }
                PageInfo<DeviceObdBaseInfo> pageInfo = new PageInfo<>(baseList);
                PageResult<List<GetDeviceListInAppVO>> build = PageResult.<List<GetDeviceListInAppVO>>builder().result(voList).pageInfo(pageInfo).build();
                return Result.suc(build);
            } else if (userType == Constants.SysUserUserType.TYPE_播种机生产厂家) {
                GetDevicePmdBaseInfoDO getDevicePmdBaseInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdBaseInfoDO.class);
                getDevicePmdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                getDevicePmdBaseInfoDO.setSortRow("createTime");
                List<DevicePmdBaseInfo> baseList = devicePmdBaseInfoService.getPageList(getDevicePmdBaseInfoDO);
                if (baseList != null && baseList.size() > 0) {
                    baseList.forEach(item -> {
                        GetDeviceListInAppVO vo = EntityConversionUtil.copy(item, GetDeviceListInAppVO.class);
                        vo.setDeviceType(Constants.DeviceType.TYPE_播种机);
                        vo.setDeviceId(item.getId());
                        voList.add(vo);
                    });
                }
                PageInfo<DevicePmdBaseInfo> pageInfo = new PageInfo<>(baseList);
                PageResult<List<GetDeviceListInAppVO>> build = PageResult.<List<GetDeviceListInAppVO>>builder().result(voList).pageInfo(pageInfo).build();
                return Result.suc(build);
            }
        }
        return null;
    }

    @Log(title = "设备管理-APP终端分布", businessType = BusinessType.INSERT)
    @ApiOperation(value = "APP终端分布")
    @PostMapping("/getDistributionListInApp")
    public Result<List<GetDeviceDistributionInAppVO>> getDeviceDistributionInApp(@RequestBody @Valid GetDeviceDistributionInAppDTO dto) {
        SysUser sysUser = sysUserService.getByUserId(dto.getUserId());
        List<GetDeviceDistributionInAppVO> voList = new ArrayList<>();
        if (sysUser != null) {
            int userType = sysUser.getUserType();
            if(userType == Constants.SysUserUserType.TYPE_TBOX生产厂家 || userType == Constants.SysUserUserType.TYPE_TBOX生产厂家2){
                GetDeviceObdBaseInfoDO getDeviceObdBaseInfoDO = new GetDeviceObdBaseInfoDO();
                if (!"testadmin".equals(sysUser.getName()))
                    getDeviceObdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                getDeviceObdBaseInfoDO.setSortRow("createTime");
                getDeviceObdBaseInfoDO.setLon("1");
                List<DeviceObdBaseInfo> baseList = deviceObdBaseInfoService.getAllList(getDeviceObdBaseInfoDO);
                if (baseList != null && baseList.size() > 0) {
                    baseList.forEach(item -> {
                        GetDeviceDistributionInAppVO vo = EntityConversionUtil.copy(item, GetDeviceDistributionInAppVO.class);
                        vo.setDeviceType(Constants.DeviceType.TYPE_TBOX);
                        voList.add(vo);
                    });
                }
            } else if (userType == Constants.SysUserUserType.TYPE_播种机生产厂家) {
                GetDevicePmdBaseInfoDO getDevicePmdBaseInfoDO = EntityConversionUtil.copy(dto, GetDevicePmdBaseInfoDO.class);
                getDevicePmdBaseInfoDO.setFactoryUserId(sysUser.getUserId());
                getDevicePmdBaseInfoDO.setSortRow("createTime");
                getDevicePmdBaseInfoDO.setLon("1");
                List<DevicePmdBaseInfo> baseList = devicePmdBaseInfoService.getAllList(getDevicePmdBaseInfoDO);
                if (baseList != null && baseList.size() > 0) {
                    baseList.forEach(item -> {
                        GetDeviceDistributionInAppVO vo = EntityConversionUtil.copy(item, GetDeviceDistributionInAppVO.class);
                        vo.setDeviceType(Constants.DeviceType.TYPE_播种机);
                        if (item.getLastDataTime() != null) vo.setDataTime(item.getLastDataTime());
                        voList.add(vo);
                    });
                }
            }
        }
        return Result.suc(voList);
    }
}
